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
 General SQL Server Forums
 New to SQL Server Programming
 INSERT Command

Author  Topic 

paramu
Posting Yak Master

151 Posts

Posted - 2009-03-04 : 05:05:48
I want to repair the following Insert Command.

insert into emp_master (emp_id,first_name,passport_no) select ?ep_id,
?fr_name,?pass_p from johu1 where ?RTRIM(ep_id) not in RTRIM(emp_id)

Thanks

Paramu @ PARANTHAMAN

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-04 : 05:15:34
do u want this
insert into emp_master (emp_id,first_name,passport_no) select ?ep_id,
?fr_name,?pass_p from johu1 where RTRIM(ep_id) not in (select RTRIM(emp_id)
from emp_master )


insert into emp_master (emp_id,first_name,passport_no) select ?ep_id,
?fr_name,?pass_p from johu1 where not exists (select * from emp_master where RTRIM(emp_id) = rtrim(ep_id))
Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2009-03-04 : 07:38:50
But Iam having SQL SERVER 2005

Paramu @ PARANTHAMAN
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-04 : 07:58:48

it will work in sql server 2005
insert into table (col1,col2,...) select
col1,col2,.... from targettable t
where not exitst (select * from table where col1 = t.col1)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-04 : 08:28:22
quote:
Originally posted by paramu

I want to repair the following Insert Command.

insert into emp_master (emp_id,first_name,passport_no) select ?ep_id,
?fr_name,?pass_p from johu1 where ?RTRIM(ep_id) not in RTRIM(emp_id)

Thanks

Paramu @ PARANTHAMAN


whats the purpose of ? marks before column names?
Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2009-03-04 : 09:15:36
To bklr: Pls....check & give with confirmed reply. It's not working for me. It's saying error nearer to 'Select' statement. But the first

insert into emp_master (emp_id,first_name,passport_no) select ep_id,fr_name,pass_p from johu1 where RTRIM(ep_id) not in (select RTRIM(emp_id)
from emp_master )

is executed but [0] rows affected........So please check ..............

PTS: just the ? for using it from VFP9 _ But now I check directly in SQL SERVER 2005.



Paramu @ PARANTHAMAN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-04 : 09:19:41
[code]
insert into emp_master (emp_id,first_name,passport_no)
select j.ep_id,j.fr_name,j.pass_p
from johu1 j
where not exists (select 1 from emp_master where RTRIM(emp_id) = rtrim(j.ep_id))
[/code]
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-04 : 09:23:26
just try this
i have given u some sample data
declare @t table (col1 int, col2 varchar(20))
insert @t
select 8244,'C' union all
select 8504,'C' union all
select 8554,'C'

declare @temp table(col1 int,col2 varchar(32))
insert into @temp
select 8244,'sampledata'

insert into @temp (col1,col2)
select
col1,col2 from @t t
where not exists (select * from @temp where col1 = t.col1)

select * from @temp

insert into @temp (col1,col2)
select
col1,col2 from @t t
where col1 not in (select col1 from @temp )

select * from @temp

In my previous query its just spelling mistake exitst as 'exists' (typing mistake)
Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2009-03-04 : 09:55:14
Fine...!!!!! , Thanks & Best Wishes & Appreciated

Paramu @ PARANTHAMAN
Go to Top of Page
   

- Advertisement -