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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help on Join

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 tables
Table 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 ..

Chirag

http://www.chirikworld.com
Go to Top of Page

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 tables
Table 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 b
LEFT OUTER JOIN A1 a
ON a.UserName=b.AppNames
WHERE a.UserName IS NULL
Go to Top of Page

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.AppNames
Please correct if I made it incorrect.

The result though did not bring any data.
Go to Top of Page

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.AppNames
Please 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?

Chirag

http://www.chirikworld.com
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -