Answered by:
Incorrect syntax near ')'

Question
-
User-1693623980 posted
Hi,
I got this error
Incorrect syntax near ')'.
and this is my query
what's wrong here?
string sql = @"SELECT * FROM ( select * from ( SELECT TOP 100 PERCENT * FROM tbl_adv WHERE Stars = 7 and IsSpecial=1 and Confirm='1' and show=1 and ExpireDate >=@ExpireDate ORDER BY NEWID()) a UNION select * from ( SELECT TOP 84 PERCENT * FROM tbl_adv WHERE Stars = 6 and IsSpecial=1 and Confirm='1' and show=1 and ExpireDate >=@ExpireDate ORDER BY NewId()) b UNION select * from ( SELECT TOP 72 PERCENT * FROM tbl_adv WHERE Stars = 5 and IsSpecial=1 and Confirm='1' and show=1 and ExpireDate >=@ExpireDate ORDER BY NewId()) c UNION select * from ( SELECT TOP 60 PERCENT * FROM tbl_adv WHERE Stars = 4 and IsSpecial=1 and Confirm='1' and show=1 and ExpireDate >=@ExpireDate ORDER BY NewId()) d UNION select * from ( SELECT TOP 48 PERCENT * FROM tbl_adv WHERE Stars = 3 and IsSpecial=1 and Confirm='1' and show=1 and ExpireDate >=@ExpireDate ORDER BY NewId()) e UNION select * from ( SELECT TOP 36 PERCENT * FROM tbl_adv WHERE Stars = 2 and IsSpecial=1 and Confirm='1' and show=1 and ExpireDate >=@ExpireDate ORDER BY NewId()) f UNION select * from ( SELECT TOP 24 PERCENT * FROM tbl_adv WHERE Stars = 1 and IsSpecial=1 and Confirm='1' and show=1 and ExpireDate >=@ExpireDate ORDER BY NewId()) g UNION select * from ( SELECT TOP 12 PERCENT * FROM tbl_adv WHERE Stars = 0 and IsSpecial=1 and Confirm='1' and show=1 and ExpireDate >=@ExpireDate ORDER BY NewId()) h ) results ORDER BY results.Stars DESC, results.UpdateDate DESC";
thanks a lot!
Monday, July 25, 2016 10:40 AM
Answers
-
User1242245693 posted
I don't think any error is there in the query
Such unexpected problems can appear when you copy the code from a web page or email and the text contains unprintable characters like space etc.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, July 25, 2016 10:57 AM
All replies
-
User1242245693 posted
I don't think any error is there in the query
Such unexpected problems can appear when you copy the code from a web page or email and the text contains unprintable characters like space etc.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, July 25, 2016 10:57 AM -
User-1693623980 posted
no i dont copy it frome anywhre else I wrote it
Monday, July 25, 2016 11:04 AM -
User-1693623980 posted
when I run this query in sql management studio directly it works fine, but when I use it in visual studio (my asp.net application) I got that error!
SELECT * FROM ( select * from ( SELECT TOP 100 PERCENT * FROM tbl_adv WHERE Stars = 7 and IsSpecial=1 and Confirm='1' and show=1 ORDER BY NEWID()) a UNION select * from ( SELECT TOP 84 PERCENT * FROM tbl_adv WHERE Stars = 6 and IsSpecial=1 and Confirm='1' and show=1 ORDER BY NewId()) b UNION select * from ( SELECT TOP 72 PERCENT * FROM tbl_adv WHERE Stars = 5 and IsSpecial=1 and Confirm='1' and show=1 ORDER BY NewId()) c UNION select * from ( SELECT TOP 60 PERCENT * FROM tbl_adv WHERE Stars = 4 and IsSpecial=1 and Confirm='1' and show=1 ORDER BY NewId()) d UNION select * from ( SELECT TOP 48 PERCENT * FROM tbl_adv WHERE Stars = 3 and IsSpecial=1 and Confirm='1' and show=1 ORDER BY NewId()) e UNION select * from ( SELECT TOP 36 PERCENT * FROM tbl_adv WHERE Stars = 2 and IsSpecial=1 and Confirm='1' and show=1 ORDER BY NewId()) f UNION select * from ( SELECT TOP 24 PERCENT * FROM tbl_adv WHERE Stars = 1 and IsSpecial=1 and Confirm='1' and show=1 ORDER BY NewId()) g UNION select * from ( SELECT TOP 12 PERCENT * FROM tbl_adv WHERE Stars = 0 and IsSpecial=1 and Confirm='1' and show=1 ORDER BY NewId()) h ) Results ORDER BY Results.Stars DESC, Results.UpdateDate DESC
Monday, July 25, 2016 11:25 AM -
User-1693623980 posted
thanks Nishant,
the error was related to another methodes in masterpage.
excuse me, thanks
Monday, July 25, 2016 11:33 AM