944,181 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Marked Solved
  • Views: 1108
  • MS SQL RSS
Oct 16th, 2009
0

Small MSSQL problem

Expand Post »
I'm using this piece of code to get the number of search results. However it says- Incorrect syntax near ')' (the very last ')' )
MS SQL Syntax (Toggle Plain Text)
  1. SELECT COUNT(*) FROM
  2. (SELECT ID, ProductDescription FROM Products WHERE ProductDescription LIKE '%tech%')
The inner select works fine and gives correct results, so I don't understand what's the problem... I won't be surprised if it's something stupid, but I've tried lots of things but with no success..
So I hope you guys can give some hints.
Last edited by Wiizl; Oct 16th, 2009 at 8:14 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Wiizl is offline Offline
25 posts
since Jan 2007
Oct 16th, 2009
1
Re: Small MSSQL problem
You need to name the table alias in your sub select.

This will fail:
sql Syntax (Toggle Plain Text)
  1. SELECT Count(*)
  2. FROM (SELECT * FROM sysobjects)

This will work:
Select Count(*)
From (Select * From sysobjects) as tbl

Just stick an "as tblName" clause regardless of whether you use it.

In the future please post Microsoft SQL Questions to the MSSQL Forum.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Oct 16th, 2009
0
Re: Small MSSQL problem
Thank you very much!!!
Reputation Points: 10
Solved Threads: 0
Light Poster
Wiizl is offline Offline
25 posts
since Jan 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Help with the Following Logic
Next Thread in MS SQL Forum Timeline: Need help on data addition





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC