Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
simonchia
Starting Member
11 Posts |
Posted - 2004-07-04 : 20:21:50
|
| greetings, i need to split a string value from a column e.g999999, 888888, 777777, 111111, 222222 and store these values into a temp table or such. anyway, i've successfully split em... BUT... if its only "999999" without the comma. it wont split cause i'm using CHARINDEX and requestion CHARINDEX to look for this value ",". how can i solve this. plz dont ask me to use parsename cause its only good up for 4 values. below are my code... need advice.CREATE PROCEDURE pr_DISTI_CMF_NO (@loginId nchar(10)) AS DECLARE @intNextCnt intDECLARE @intStart intDECLARE @intLen intDECLARE @subString nchar(10)SET @intNextCnt = 1SET @intStart = 0SET @intLen = 0--create the tmp table to store the split valueCREATE TABLE #tmpCMF( CMFNo nchar(10))WHILE (@intNextCnt <> 0) BEGIN SELECT @intNextCnt = CHARINDEX(',', usr_cmf_num, @intNextCnt + 1) FROM CPM WHERE Login_Id = @loginid SELECT @subString = SUBSTRING(usr_cmf_num, @intStart ,CHARINDEX(',', usr_cmf_num)) FROM CPM WHERE Login_Id = @loginid SET @intStart = @intNextCnt + 1 print @intStart INSERT INTO #tmpCMF VALUES(LTRIM(@subString))ENDSELECT cmf.cust_id, cmf.disti_id, a.cust_lvl_2_nm FROM cmf, (SELECT CMF.cust_id, #TMPCMF.cmfno, CMF.Disti_ID, Disti.cust_lvl_2_nm FROM CMFINNER JOIN #TMPCMF ON Right(CMF.cust_id, 6) = #TMPCMF.cmfnoINNER JOIN Disti ON CMF.Disti_ID = Disti.Disti_ID) aWHERE cmf.disti_id = a.disti_idGROUP BY a.cust_lvl_2_nm, cmf.cust_id, cmf.disti_id ORDER BY a.cust_lvl_2_nm ASCDROP table #TMPCMFGO |
|
|
MichaelP
Jedi Yak
2489 Posts |
|
|
simonchia
Starting Member
11 Posts |
Posted - 2004-07-04 : 22:19:10
|
| nop i have not.. but thanks. |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-07-04 : 22:44:02
|
| just add a comma to the end...Corey |
 |
|
|
|
|
|
|
|