Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
HiIn the below query i have to retreive '212012,212713,212749' empid's from table1 first. and then i can retreive anyother empid from table1i have created the below query but its not retrieving. can anyone help for this?SELECT TOP 4 * FROM ( SELECT * FROM table1 UNIONSELECT * FROM table1 WHERE empid IN (SELECT SaparaterID from dbo.fn_SplitCommaSeparatedValues('212012,212713,212749'))) eVisa.G
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2011-07-20 : 05:40:38
You must have something to denote order. Tables doesn't have a physical order to rely on, only logical order.
SELECT TOP(4) *FROM ( SELECT 1 AS theOrder, * FROM table1 UNION ALL SELECT 2 AS theOrder, t1.* FROM table1 AS t1 INNER JOIN dbo.fn_SplitCommaSeparatedValues('212012,212713,212749') AS t2 ON t2.SaparaterID = t1.empid ) AS eORDER BY theOrder
N 56°04'39.26"E 12°55'05.63"
visa123
Yak Posting Veteran
54 Posts
Posted - 2011-07-20 : 05:48:40
Yes i got it.I did one mistake in this QuerySELECT TOP 4 * FROM(SELECT 1 as Sortorder ,* FROM table1UNIONSELECT 2 as Sortorder,* FROM table1 WHERE empid IN (SELECT SaparaterID from dbo.fn_SplitCommaSeparatedValues('212012,212713,212749'))) e order by SortOrderVisa.G