Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT INTO, but specifiying a value as well.

Status
Not open for further replies.

aBill

MIS
Sep 24, 2002
26
US
I need to select all of the rows in a given table that match a criteria, and them add them back onto the same table while specifying a third value.

It's a three column table (a, b, c) and all three make the key.

I need to select a, b, where c=1 and append them to the same table while making c=2 for each.

The actual new value for C is being passed in via a stored procedure input parameter. Can anyone help me out on this one? I could just bring the tbal into my application, loop through it and insert the new rows, but i thought that there might be a better pure SQL/DTS way to go about it.

Thanks in Advance.

 
Something like this should do the trick.

Code:
Insert Into <Table> (a,b,c)
Select a,b,@NewValueForC From <table> Where c = @OldValueOfC

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
You would think so, wouldn't you. I have tried it, and SQL is screaming... giving me an "ADO Error: Syntax error or access violation" error.

Here is the actualy code.

SELECT document_groups_members.group_id, document_groups_members.document_id, @job_id
FROM document_groups_members INNER JOIN
documents ON document_groups_members.document_id = documents.document_id
WHERE (documents.default_job_document = 'Y') AND IS NULL(document_group_members.job_id)
 
Code:
WHERE documents.default_job_document = 'Y'
  AND document_group_members.job_id IS NULL

--James
 
yeah, thanks, noticed that one. The SQL analyser hashed my code pretty good hopping between it and VS.NET.

I'll post back if it's still messed up.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top