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 2008 Forums
 Transact-SQL (2008)
 Repeating insert command

Author  Topic 

abenitez77
Yak Posting Veteran

53 Posts

Posted - 2010-05-03 : 12:57:40
I have this insert statement which will be used and reused many times. I am using SQL Server 2008. How can I turn this into a stored procedure that can be called and used? The 2 fields that will need to use variables to update them are (GroupVendor and GroupType). In the Where clause I will need variable(s) to use there as well.

TSQL Code:

Insert Into dbo.CMS_NewVnd_Master(
[Site_NBR], [AuditCode], [AuditDesc], [PRGIndustryDesc],
[PRGSubIndustryDesc], [CorpClientDesc], [AuditStatus], [Client_Nbr],
[AuditYearDesc], [VendorCode], [VendorDesc], New_Vnd, New_Name,
GroupVendor,
GroupType)
(Select [Site_NBR], [AuditCode], [AuditDesc], [PRGIndustryDesc],
[PRGSubIndustryDesc], [CorpClientDesc], [AuditStatus], [Client_Nbr],
[AuditYearDesc], [VendorCode], [VendorDesc], New_Vnd, New_Name,
'Blackhawk Network', 'GiftCard'
From tblv_Claims_2006AndGreater
Where VendorDesc Like 'Blackhawk Net%' OR VendorDesc Like 'Blackhawk Mark%' OR
VendorDesc Like 'BLACKHAWK MRKTG%')

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-03 : 13:07:34
[code]Insert Into dbo.CMS_NewVnd_Master(
[Site_NBR], [AuditCode], [AuditDesc], [PRGIndustryDesc],
[PRGSubIndustryDesc], [CorpClientDesc], [AuditStatus], [Client_Nbr],
[AuditYearDesc], [VendorCode], [VendorDesc], New_Vnd, New_Name,
GroupVendor,
GroupType)
(Select [Site_NBR], [AuditCode], [AuditDesc], [PRGIndustryDesc],
[PRGSubIndustryDesc], [CorpClientDesc], [AuditStatus], [Client_Nbr],
[AuditYearDesc], [VendorCode], [VendorDesc], New_Vnd, New_Name,
@GroupVendor, @GroupType
From tblv_Claims_2006AndGreater
Where VendorDesc Like 'Blackhawk Net%' OR VendorDesc Like 'Blackhawk Mark%' OR
VendorDesc Like 'BLACKHAWK MRKTG%') [/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

abenitez77
Yak Posting Veteran

53 Posts

Posted - 2010-05-03 : 14:56:59
how about at the where command line? (Where VendorDesc Like 'Blackhawk Net%' ). That will change all the time depending on the vendor. There could be 1 or 10 different variations I have to check for. How can i automate that into a procedure so i can reuse the code without changing it?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-04 : 04:15:06
where does those value come from? a table or a variable?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -