![]() |
|
![]() | ||
|
Subject:
SQL Query Question
Category: Computers > Software Asked by: marcfarmen-ga List Price: $10.00 |
Posted:
10 Feb 2006 13:56 PST
Expires: 28 Feb 2006 14:11 PST Question ID: 444287 |
I am attempting to write a simple update query that will automatically be ran ever hour to update a records based on another columns value. The below code works. UPDATE Client SET Organisation = '3' WHERE (Address LIKE '01%') UPDATE Client SET Organisation = '4' WHERE (Address LIKE '02%') UPDATE Client SET Organisation = '5' WHERE (Address LIKE '03%') UPDATE Client SET Organisation = '6' WHERE (Address LIKE '04%') UPDATE Client SET Organisation = '7' WHERE (Address LIKE '05%') ???Until I get to 99????. UPDATE Client SET Organisation = '97' WHERE (Address LIKE '99%') I would like to automate this process to look in the DB every hour and change UPDATE the Orginisation Colum. I looked at Stored Procedures but and lost. The Client table can be pretty large as many as 100,000 records. What is the most efficient way to accomplish this task. Any help would be greatly appreciated. Thanks Marc Farmen mfarmen@centennial-software.com | |
| |
|
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
Subject:
Re: SQL Query Question
From: applehead77-ga on 10 Feb 2006 22:52 PST |
Hi Marc, In my opinion, creating an 'Update Trigger' AND/OR an 'Insert Trigger' on the source table is a better option than creating a 'scheduled job'. On every insert/update to the table, the appropriate sql statement can be executed. Here's some code (Insert trigger) to get you started: ---------------------- CREATE trigger tr_insert_source on Source_Table for insert as declare @address varchar(100) declare @sql varchar(100) SELECT @address = i.Address FROM inserted i select @sql = case left(@address,2) when '01' then "Update client set Organization=3 where Address like '01%'" when '02' then "Update client set Organization=5 where Address like '02%'" ... ... End exec(@sql) Note that if there is a pattern/relationship between Address and Organization (It looks as though Organization = Int(Address) + 2), you can write a TSql script that does this... Something that looks like : declare @Id int declare @Len varchar(10) declare @zeroFill varchar(10) declare @like varchar(10) declare @organization varchar(10) declare @sql varchar(100) select @Len = len(cast (@Id as char)) select @zeroFill = replicate('0',2-cast(@Len as int)) + cast(@Id as varchar(10)) set @organization = cast(@zeroFill as int) + 2 set @like = @zeroFill + '%' set @sql= 'Update Client set Organization=' + char(39) + @organization + char(39) + ' where Address like ' + char(39) + @like + char(39) exec (@sql) I hope this helps... |
Subject:
Re: SQL Query Question
From: sirkermit-ga on 23 Feb 2006 06:20 PST |
If you're willing to run extra programs on the server it would probably take you about 30 mins to learn enough C# to write this VERY simple program + you'll be able to add as many new queries as you want for any timing you want. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |