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 |
|
CoolEJ
Starting Member
7 Posts |
Posted - 2008-01-23 : 03:15:14
|
| Hi, I really need your help on this. I have two tablesTable A1 with columns RecordID1 and UserName.Table B2 with columns Task1 and AppNames.A user procedure creates a record from Table B2 to A1 by copying Task1 to RecordID1 and AppNames to UserName.My problem is: How do I query for the AppNames that are not present in table A1.It sounds simple, but I am having some problem getting the code right. By the way, only statements, that start with SELECT, are allowed by the system. Please help me on this one.Thanks in advance. |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2008-01-23 : 03:31:30
|
| [code]Insert A1 (RecordID1 ,UserName)Select Task1, AppNames From B2 Where Not Exists( Select 1 From A1 Where A1.RecorID1 = B2.Task1 And A1.UserName = B2.AppNames)[/code]Hope this should work with you ..Chiraghttp://www.chirikworld.com |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-23 : 03:52:51
|
quote: Originally posted by CoolEJ Hi, I really need your help on this. I have two tablesTable A1 with columns RecordID1 and UserName.Table B2 with columns Task1 and AppNames.A user procedure creates a record from Table B2 to A1 by copying Task1 to RecordID1 and AppNames to UserName.My problem is: How do I query for the AppNames that are not present in table A1.It sounds simple, but I am having some problem getting the code right. By the way, only statements, that start with SELECT, are allowed by the system. Please help me on this one.Thanks in advance.
SELECT b.Task1,b.AppNames FROM B2 bLEFT OUTER JOIN A1 aON a.UserName=b.AppNamesWHERE a.UserName IS NULL |
 |
|
|
CoolEJ
Starting Member
7 Posts |
Posted - 2008-01-23 : 03:55:56
|
| Hi Chirag, Thanks for the reply. "Select 1 From A1 Where A1.RecorID1 = B2.Task1 And A1.UserName = B2.AppNames"I tried to correct some parts: SELECT B2.Task1 FROM A1, B2 WHERE A1,RecordID1=B2.Task1 AND A1.UserName=B2.AppNamesPlease correct if I made it incorrect.The result though did not bring any data. |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2008-01-23 : 04:00:41
|
quote: Originally posted by CoolEJ Hi Chirag, Thanks for the reply. "Select 1 From A1 Where A1.RecorID1 = B2.Task1 And A1.UserName = B2.AppNames"I tried to correct some parts: SELECT B2.Task1 FROM A1, B2 WHERE A1,RecordID1=B2.Task1 AND A1.UserName=B2.AppNamesPlease correct if I made it incorrect.The result though did not bring any data.
The query which i gave you, will only insert the records in the table which are not present.. Did the query which i gave, generated any problems..??? since i m not sure what u r trying to do by changing the query?Chiraghttp://www.chirikworld.com |
 |
|
|
CoolEJ
Starting Member
7 Posts |
Posted - 2008-01-23 : 04:26:46
|
Hi Chira, Sorry I did not notice the Insert Part .But the system can only accept SELECT.Visakh, The data came out right. I knew I was missing out something. I tried to use NULL before but maybe in the wrong way.Thanks a lot!Thanks to both of you. Have a great day. |
 |
|
|
|
|
|
|
|