SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 how to pick the number and make it as first
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/09/2013 :  08:14:07  Show Profile  Reply with Quote
hello all

i had a query in which i written my main requirement is

1 - 2 - 3 it is the sequence

if i pick 2
then sequence must be 2 - 3 - 1

if i pick 3
then sequence must be 3- 1- 2

my 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 @PhotoNames



P.V.P.MOhan

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 01/09/2013 :  09:40:37  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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.
Go to Top of Page

Jeff Moden
Aged Yak Warrior

USA
649 Posts

Posted - 01/09/2013 :  20:28:24  Show Profile  Reply with Quote
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 sequence

if i pick 2
then sequence must be 2 - 3 - 1

if i pick 3
then sequence must be 3- 1- 2

my 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 @PhotoNames



P.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."
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/09/2013 :  22:49:07  Show Profile  Reply with Quote
to me it sounds like a CASE expression based ORDER BY in your select to get output in order that you want

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/09/2013 :  23:43:23  Show Profile  Reply with Quote
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 - 1

P.V.P.MOhan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/10/2013 :  00:25:12  Show Profile  Reply with Quote
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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000