Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need an SQL Statement that Selects from source table into target. I did the following :

 

SELECT * INTO TargTable FROM SoTable Where TID = 'value'

 

It just works fine for a non existing table. But i´ll have to do it several times in an existing table.

 

Any ideas ??

Sometimes you´ve got to make a silent Takedown .
Posted

From your example, the syntax is:

INSERT INTO TargTable

SELECT * FROM SoTable

Where TID = 'value'

 

This of course assumes that TargTable and SoTable have the same layout, otherwise, you'd have to replace "*" with the list of columns you want the data from. In fact, you may have to do that anyway, I haven't tried this in a while.

Posted
Just tried it, you can use "*" if the layout is the same, although select "*" is never a best-practice. I just used it here since I didn't have a column listing in his example.
Posted

And your tables had the same field layout? I used two tables with a single Char(10) column and put one record into Table1, then ran:

insert into dbo.Table2

select * from dbo.Table1

 

 

and checked and found one row in Table2. Weird that it didn't work for you - maybe it depends on column types for this?

Posted

Ah, that makes sense then.

 

I actually had an issue yesterday with a DTS pack not working because of an Identity column. Gave a lovely "Unspecified Error" message when it didn't work. So I had to figure out why one out of 5 tables wouldn't load and that's what it came down to. Damn Identities!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...