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 |
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-01-09 : 08:14:07
|
hello all i had a query in which i written my main requirement is 1 - 2 - 3 it is the sequenceif i pick 2 then sequence must be 2 - 3 - 1 if i pick 3then sequence must be 3- 1- 2my query is :DECLARE @PhotoNames VARCHAR(800) select @PhotoNames=COALESCE(@PhotoNames + '-', '') + PhotoName FROM Cust_Photos where Cust_ID=2 and IsActive=1 and PhotoName is not null select @PhotoNamesP.V.P.MOhan |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2013-01-09 : 09:40:37
|
What are your 1,2 and 3?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
Jeff Moden
Aged Yak Warrior
652 Posts |
Posted - 2013-01-09 : 20:28:24
|
quote: Originally posted by mohan123 hello all i had a query in which i written my main requirement is 1 - 2 - 3 it is the sequenceif i pick 2 then sequence must be 2 - 3 - 1 if i pick 3then sequence must be 3- 1- 2my query is :DECLARE @PhotoNames VARCHAR(800) select @PhotoNames=COALESCE(@PhotoNames + '-', '') + PhotoName FROM Cust_Photos where Cust_ID=2 and IsActive=1 and PhotoName is not null select @PhotoNamesP.V.P.MOhan
BWAAAA-HAAA!!!! Selecting sequences in the order that you describe isn't difficult but go back and read your own post and understand why I ask what you really want. You're code doesn't even have anything about it.--Jeff Moden RBAR is pronounced "ree-bar" and is a "Modenism" for "Row By Agonizing Row".First step towards the paradigm shift of writing Set Based code:"Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column." When writing schedules, keep the following in mind:"If you want it real bad, that's the way you'll likely get it." |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-09 : 22:49:07
|
to me it sounds like a CASE expression based ORDER BY in your select to get output in order that you want------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-01-09 : 23:43:23
|
like in the front end if they 2 nd image the sequence should come like 2 - 3 - 1 if they select 3 rd image the sequence should come like 3 - 2 - 1P.V.P.MOhan |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 00:25:12
|
Assuming image sequence number is passed as a parameter you can use like this...ORDER BY CASE WHEN SeqNo=@PassedSeqNo THEN 1 ELSE 2 END ASC ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|