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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Procedure Questions

Author  Topic 

timsweet
Starting Member

31 Posts

Posted - 2005-08-31 : 13:28:03
I need to update a table with a pull (select) from another table.

So I have

Insert into tblActivity_Temp (abr_id, RecordUpdatedDate,
RecordUpdateduser)
Select T1.Abr_id, T1.RecordUpdatedDate, T1.RecordUpdatedUser
From tblPeople as T1
Where T1.RecordUpdatedDate >= { fn CURDATE() }

That works great.

Now with this same code I want to set a field that is not in the Select query but is in the temp table to a hard coded value.


Is that possible?

Thanks in advance.

SamC
White Water Yakist

3467 Posts

Posted - 2005-08-31 : 13:34:25
quote:
Originally posted by timsweet

Now with this same code I want to set a field that is not in the Select query but is in the temp table to a hard coded value.

Is that possible?
Yes.

What's the name of the field and the table?

Something like

INSERT INTO MyTable (Col1, Col2, Col3)
SELECT ColB, ColC, (SELECT Hard_Coded_Value FROM #MyTemp)
FROM TableB
Go to Top of Page

timsweet
Starting Member

31 Posts

Posted - 2005-08-31 : 13:53:12
SAMC - Thanks

My select (source table) will give me 3 of the 4 values I need to insert into the temp table.

The 4th value I want to insert will be hard coded not part of select.

Source table fields abr_id, RecordUpdatedDate, RecordUpdateduser

target table fields abr_id, RecordUpdatedDate, RecordUpdateduser, Acitivty

My select will get me the first 3 and I need to set the filed Activity to a set value.


Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-08-31 : 14:23:55
quote:
Originally posted by timsweet

Source table fields abr_id, RecordUpdatedDate, RecordUpdateduser

target table fields abr_id, RecordUpdatedDate, RecordUpdateduser, Acitivty

My select will get me the first 3 and I need to set the filed Activity to a set value.


Just hard-code the Activity value in the SELECT then.

INSERT INTO MyTable (Col1, Col2, Col3, Col4)
SELECT ColA, ColB, ColC, 5 -- or SELECT ColA, ColB, ColC, @ActivityValue
FROM AnotherTable
Go to Top of Page

timsweet
Starting Member

31 Posts

Posted - 2005-08-31 : 15:51:21
Thats for the assistance...here is what worked.

Create Procedure sp_filltblActivity_temp2
as

Declare @activity as nvarchar(50)
Set @activity = 'contact'

Insert into tblActivity_Temp (abr_id, RecordUpdatedDate, RecordUpdateduser, Activity)



Select T1.Abr_id, T1.RecordUpdatedDate, T1.RecordUpdatedUser, @activity
From tblContact as T1
Where T1.RecordUpdatedDate >= { fn CURDATE() }
go


Regards
Tim Sweet
Go to Top of Page
   

- Advertisement -