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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to write stored procedure

Author  Topic 

spshindagi
Starting Member

11 Posts

Posted - 2008-01-29 : 02:19:20
hello,
i have the following table
sno Accsno a1 a2 a3 a4 b1 b2 b3 b4.........z1 z2 z3 z4
1 aa1 0 2 0 A 1 0 3 B 1 2 3 Z
2 aa1 1 0 3 A1 0 2 0 B1 0 0 0 Z1
3 aa2 0 2 0 A 1 0 3 B 1 2 3 Z
4 aa2 1 0 3 A1 0 2 0 B1 0 0 0 Z1

@param1="1,2,3"and param2="a1,b1,a2,c2" and param3="aa1"
i wanted to retirve a4 if a1='1'
b4 if b1='1'
a4 if a2='2'
c4 if c2='2'
i.e dynamically selection of column name

love all

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-29 : 02:27:52
maybe Dynamic SQL ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-01-29 : 02:28:10
Seems like duplicate post with modified content.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=95449

Did you go through the link Madhivanan provided. Seems not.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-01-30 : 02:14:15
The alternative is using CASE in your SELECT statments - this would still return the columns , but you could manage the values returning in the columns

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -