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 |
|
iamsmahd
Yak Posting Veteran
55 Posts |
Posted - 2006-06-14 : 07:09:38
|
| hi all,I wanna to have a select query which its order by part dinamically changes based on the option that user selects from a combo box of form.....I have written this query but as it seems it is not correct::declare @n varchar(70)set @n = 'PersonNumber'select * from dbo.Persons order by @nwhat is your solutions? tanks in advancesonia |
|
|
vallis
Starting Member
12 Posts |
Posted - 2006-06-14 : 07:12:59
|
| declare @n varchar(70)set @n = 'PersonNumber'EXEC('select TOP 50 * from dbo.Persons order by ' + @n) |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-06-14 : 07:20:21
|
| http://www.sqlteam.com/item.asp?ItemID=2209Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-14 : 08:54:45
|
quote: Originally posted by vallis declare @n varchar(70)set @n = 'PersonNumber'EXEC('select TOP 50 * from dbo.Persons order by ' + @n)
Dynamic SQL is not needed. Refer the link posted by RyanMadhivananFailing to plan is Planning to fail |
 |
|
|
iamsmahd
Yak Posting Veteran
55 Posts |
Posted - 2006-06-14 : 10:03:26
|
| THANK YOU VERY MUCHsonia |
 |
|
|
|
|
|