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 |
archana23
Yak Posting Veteran
89 Posts |
Posted - 2013-04-24 : 15:12:17
|
Hello,I am new to writing queries in Sql, I have two tables like GetReports(ReportName, Url,ReportId,DeptId as columns) and UserDepts(UserName,DeptId as columns) tables.My requiement is i need to get the data from GetReports table if DeptId is exist in UserDepts for particular UserNameso for that i tried with below query but getting error saying that "Incorrect syntax near keyword Where"select * from GetReports where ReportID = 5 and DeptId in (select DeptId from UserDepts where UserName ='abc')Can you please help me on this?Archana |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-04-24 : 15:31:38
|
You may want to try something like this:[CODE]SELECT ReportName, Url, ReportId, DeptId from GetReports T1 inner join UserDepts T2 on T1.DeptId = T2.DeptId and T2.UserName = 'abc';[/CODE] |
|
|
archana23
Yak Posting Veteran
89 Posts |
Posted - 2013-04-24 : 16:11:33
|
Thank you.. it worked..Archana |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-04-24 : 21:21:18
|
You are welcome. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-25 : 00:48:18
|
your original doesnt seem to have any errors. Are you sure this was the full query attempted?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|