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)
 Select same feild as diffret .... depending on som

Author  Topic 

sujithukvl@gmail.com
Starting Member

22 Posts

Posted - 2009-03-18 : 03:20:56
SELECT * FROM ( select row_number() over (order by Manufacture.ManufactureID) as Rec_num, ManufactureID FROM Manufacture WHERE DisplayLogoInSplashPage= 1)A where Rec_num%2=0



This selects ManufactureID at evn position in table.



SELECT * FROM ( select row_number() over (order by Manufacture.ManufactureID) as Rec_num, ManufactureID FROM Manufacture WHERE DisplayLogoInSplashPage= 1)A where Rec_num%2=1



This selects ManufactureID at odd position in table.


but I want both this in a single querry
like select ManufactureID as ManufactureIDOdd if Rec_num%2=1
and ManufactureID as ManufactureIDEven if Rec_num%2=0

what can I do for this?
……………………………………………………………………………………………………………………………………………………………..
If taking postion using row_number() is difficult
we may use ManufactureID%2
……………………………………………………………………………………………………………………………………………………………..

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-18 : 03:52:58
Like this?
SELECT		MAX(CASE WHEN recID % 2 = 0 THEN ManufactureID ELSE NULL END) AS evenManufactureID,
MAX(CASE WHEN recID % 2 = 1 THEN ManufactureID ELSE NULL END) AS oddManufactureID
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY ManufactureID) - 1 AS recID,
ManufactureID
FROM Manufacture
WHERE DisplayLogoInSplashPage = 1
) AS f
GROUP BY recID / 2
ORDER BY recID / 2



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

sujithukvl@gmail.com
Starting Member

22 Posts

Posted - 2009-03-19 : 02:15:12
great great thanks
i was affried that people understand my need
But u helped me
Go to Top of Page
   

- Advertisement -