Monday, March 19, 2012

Insert Statement...

Hi All,

I am trying to insert data into table1 by getting data from table2, table3 and looking whether the data is already not exist in table1.

Here is my code...

insert into table1
(first_name, last_name, user_login, email, organization_name) values
(select ru.firstname, ru.lastname, ru.UserID, ru.EmailAddress, ru.BusinessName from table2ru, table3 wepsUsers
whereru.id =wepsUsers.user_id and
not exists
(select user_login from table1
whereuser_login =ru.UserID))

When I excute the code, I am getting the following error....

Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'select'.
Server: Msg 170, Level 15, State 1, Line 7
Line 7: Incorrect syntax near ')'.

But, If execute the following code...

select ru.firstname, ru.lastname, ru.UserID, ru.EmailAddress, ru.BusinessName from table2ru, table3 wepsUsers
whereru.id =wepsUsers.user_id and
not exists
(select user_login from table1
whereuser_login =ru.UserID)... I am able to see the values.

Can any one shade on my code? and please let me know, where I am doing wrong. I am appreciate your help.

Thanks.

Srinivas.

insert into table1
(first_name, last_name, user_login, email, organization_name)
select ru.firstname, ru.lastname, ru.UserID, ru.EmailAddress, ru.BusinessName from table2ru, table3 wepsUsers
whereru.id =wepsUsers.user_id and
not exists
(select user_login from table1
whereuser_login =ru.UserID)

|||In case you don't see it right away, "values" should not be there.|||

Hi,

Thanks to every one for the help.

--Srinivas

No comments:

Post a Comment