Hello, SQL2008R2
Okay it is Friday and I just cannot think of how to do this.
What I want is to get the data that joins to a record in a second table and the data that matches criteria into a "newtable".
I would prefer not to use a union command.
I am rewriting a stored procedure that has two INSERT INTO queries.
Is there a way to combine these two queries?
Thank you,
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
Okay it is Friday and I just cannot think of how to do this.
What I want is to get the data that joins to a record in a second table and the data that matches criteria into a "newtable".
I would prefer not to use a union command.
I am rewriting a stored procedure that has two INSERT INTO queries.
Code:
-- current code
INSERT INTO NewTable (Col1, Col2, Col3, Col4, Col5)
SELECT Table1.Col1, Table1.Col2, Table1.Col3, Table1.Col4, Table1.Col5
FROM Table1
INNER JOIN Table2
ON Table1.Col1 = Table2.Col1
WHERE Table1.Col2 IS NOT NULL
AND ISNULL(Table1.Col3, '') = 'Test'
INSERT INTO NewTable (Col1, Col2, Col3, Col4, Col5)
SELECT Table1.Col1, Table1.Col2, Table1.Col3, Table1.Col4, Table1.Col5
FROM Table1
WHERE (Table1.Col4 = 'Check1' OR Table1.Col4 = 'Check2')
AND Table1.Col5 IS NOT NULL
AND ISNULL(Table1.Col3, '') = 'Test'
Thank you,
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!