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 |
|
shaoen01
Yak Posting Veteran
78 Posts |
Posted - 2012-02-16 : 05:02:24
|
Hi All,I have a situation here and i am quite stuck on what i can do. So here goes my situation.I have one table called MyTable with fields:1. type_code2. reset_pay_ind3. reset_rcv_ind4. ref15. parentrefif type_code=11 ThenDo a select type_code from MyTable Where parentref=ref1if type_code is 222 ThenReturn reset_pay_ind as 'abc'End Nested IfEnd ifAnyone knows how i should go about approaching this? I hope i do make sense.  |
|
|
shaoen01
Yak Posting Veteran
78 Posts |
Posted - 2012-02-16 : 05:13:43
|
| So the output data can be like below. Hopefully, it makes more sense:select type_code,ref1,parentref from MyTable Where type_code=11type_code ref1 parentref11 222 0select type_code,ref1,parentref from MyTable Where parentref=222type_code ref1 parentref55 0 222 |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2012-02-16 : 09:21:47
|
| Make this a stored procedure, and just check the value of the parameter when it comes in. Then you can execute whichever select you want.http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
shaoen01
Yak Posting Veteran
78 Posts |
Posted - 2012-02-16 : 18:27:49
|
| Thanks for your code.But what does below do? I tried Googling Coalesc uses and what i have read that it is similar to isnull and it uses the next non-null value or somewhere along this line?type_code = COALESCE(@type_code, type_code)The code does not cater to help update reset_pay_ind cell value?Should i consider using Cursor? |
 |
|
|
|
|
|
|
|