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
 shorter way of doing an insert & select

Author  Topic 

tariq2
Posting Yak Master

125 Posts

Posted - 2011-03-28 : 09:50:35
I am re-inserting a record which already exists in a table
and am using teh following code which works fine but was wondering if there is a quicker way of doing this? Thank you in advance



insert into F_AR

SELECT
98,docnumber,doctype,doccompany,linenumber,RPMCU,Jobkey,Bukey,LEID,CLientID,Ictypekey,
GLDATE,InvoiceDate,DueDate,lcu_invoicetotal,lcu_taxamount,lcu_currentamount,scu_currencykey,
scu_exchangerate,scu_invoicetotal,scu_currentamount,Days0To30,0,0,0,0,0,0,300


from F_AR
where DocNumber = 11000013

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-03-28 : 09:55:08
That's the way.
What should be quicker?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-28 : 10:07:13
If you are using SQL 2008 you can use MERGE


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-03-28 : 13:19:35
I don't think a Merge is going to be any shorter than a simple insert.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-28 : 20:53:31
OP said "re-inserting" .. sounds like an requirement for UPSERT. If this is the case, a single MERGE statement will do the job rather than 2 separate statement.



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-03-29 : 07:02:45
Sorry kh but I can see only one single statement in the original post.
So why change anything?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-29 : 07:25:57
oh i think i misunderstood what OP wants. My bad



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -