Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone
I'm trying to implement your solution sugesstion a stroed procedure but it keep giving me the Error
"Incorrect syntax near Keyword Group". What am i doing wrong?



SQL
 SET @Dynamictbl = N'SELECT [Products], [Price], [Finance]

 FROM (
 SELECT [Products], [Price], [Finance] FROM ' + @Table_Name + ' WHERE [Area] = ''PB''' +
' EXCEPT
 SELECT [Products], [Price], [Finance]
FROM ' + @Table_Name2 + ' WHERE [Area] = ''PB''' +
 ')' +
 ' GROUP BY [Products], [Price], [Finance]
 ORDER BY [Products] DESC '
Posted
Updated 4-Nov-14 21:31pm
v2
Comments
Thanks7872 5-Nov-14 3:36am    
I think you tried to implement code from some Article or Tip/Trick. Go to bottom of that page where you can post comment regarding issue related to code mentioned there.
mikybrain1 5-Nov-14 3:39am    
don't really understand you. That a code from me trying to implement. The problem lies ')' +

Change this:
SQL
FROM ' + @Table_Name2 + ' WHERE [Area] = ''PB''' +
 ')' +
 ' GROUP


to:
SQL
FROM ' + @Table_Name2 + ' WHERE [Area] = ''PB''' +
 ') AS T ' +
 ' GROUP


You forgot to add alias
 
Share this answer
 
Comments
Shweta N Mishra 5-Nov-14 3:41am    
+5
Maciej Los 5-Nov-14 3:44am    
Thank you ;)
King Fisher 5-Nov-14 7:38am    
5++ ;)
Maciej Los 5-Nov-14 7:38am    
Thank you ;)
Hi,
Yes you need to give name for the top selected Query

Try this hope this will work for you.

SQL
SET @Dynamictbl = N'SELECT [Products], [Price], [Finance]
 
 FROM (
 SELECT [Products], [Price], [Finance] FROM ' + @Table_Name + ' WHERE [Area] = ''PB''' +
' EXCEPT
 SELECT [Products], [Price], [Finance]
FROM ' + @Table_Name2 + ' WHERE [Area] = ''PB''' +
 ') z' +
 ' GROUP BY [Products], [Price], [Finance]
 ORDER BY [Products] DESC '


here i have added " z" before group by
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900