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 |
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2010-03-12 : 02:01:43
|
| Hi all, i have to retrive some columns and i have to take a union same columns with differnt conditiopn.for selecting condition is like this it has to take only the top one and odered by enddate desc condition .But here its shows syntax error in Union like incorrect syntax near union,is it because i am using order by clause before unioncode which i have done is like thisDECLARE @Field_ID INTSELECT TOP 1 FIS_Sub_Article.Article_ID, CONVERT(nvarchar(max),FIS_Sub_Article.Article_Title)AS Article_Title, CONVERT(nvarchar(max),FIS_Sub_Article.Abstract)AS Abstract, ISNULL(CONVERT(VARCHAR,FIS_Sub_Article_Status.End_Date , 101),'')AS PublishedDateFROM FIS_Sub_Article WITH(NOLOCK) INNER JOIN FIS_Sub_Article_Status WITH(NOLOCK) ON FIS_Sub_Article_Status.Article_ID=FIS_Sub_Article.Article_IDWHERE FIS_Sub_Article.Stage_ID=18 --AND FIS_Sub_Article.IsDeleted=0 AND FIS_Sub_Article.Field_ID =71ORDER BY FIS_Sub_Article_Status.End_Date DESCUNION SELECT TOP 1 FIS_Sub_Article.Article_ID, CONVERT(nvarchar(max),FIS_Sub_Article.Article_Title)AS Article_Title, CONVERT(nvarchar(max),FIS_Sub_Article.Abstract)AS Abstract, ISNULL(CONVERT(VARCHAR,FIS_Sub_Article_Status.End_Date , 101),'')AS PublishedDate FROM FIS_Sub_Article WITH(NOLOCK) INNER JOIN FIS_Sub_Article_Status WITH(NOLOCK) ON FIS_Sub_Article_Status.Article_ID=FIS_Sub_Article.Article_ID WHERE FIS_Sub_Article.Stage_ID=18 AND FIS_Sub_Article.IsDeleted=0 AND FIS_Sub_Article.Field_ID =86 ORDER BY FIS_Sub_Article_Status.End_Date DESCRegards,Divya |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-12 : 02:09:42
|
Use derived tables, that should work:DECLARE ...select * from(your_first_select_comes_here) as dtunionselect * from(your_second_select_comes_here) as dt2 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2010-03-12 : 02:19:10
|
quote: Originally posted by webfred Use derived tables, that should work:DECLARE ...select * from(your_first_select_comes_here) as dtunionselect * from(your_second_select_comes_here) as dt2 No, you're never too old to Yak'n'Roll if you're too young to die.
Thank you webfred it worked......Regards,Divya |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-12 : 02:34:47
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|