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 |
|
knockyo
Yak Posting Veteran
83 Posts |
Posted - 2009-12-01 : 06:55:18
|
Hi All,Below is my SQL,Select *From tbl_ItemWhere StatusId IN (1,2) Result:ItemId ItemStatus StatusId UserName------ ---------- -------- --------151588 Donated 1 User1151587 Donated 1 User1154664 Donated 1 User3155840 Scrap 2 User2155840 Scrap 2 user2Questions:How can i set the value in the UserName field = "" when the StatusId=2So I need to involve 2 function Split and While Loop? |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-12-01 : 07:03:08
|
| Hi, Try thisselect itemid,itemstatus,statusid, case when statusid = 2 then '' else username end AS usernamefrom tbl_ItemWhere StatusId IN (1,2) |
 |
|
|
knockyo
Yak Posting Veteran
83 Posts |
Posted - 2009-12-01 : 07:06:58
|
Hi,thanks your idea.but i can't direct to that because from the Select *From tbl_ItemWhere StatusId IN (1,2) excatly the where clause there is a parameterSelect *From tbl_ItemWhere StatusId IN (@StatusId) Because of that reason, i need split the @StatusId with delimiters (,) to loop the data[url=http://angel.exabytes.com.my/idevaffiliate.php?id=3204138_14_1_55] [/url] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-01 : 07:27:36
|
| Select *From tbl_ItemWhere ','+@StatusId+',' '%,'+cast(StatusId as varchar(10))+',%' MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|