Discussion:
Need help with t-sql - need to update a table
(too old to reply)
Learner
2012-01-24 16:02:35 UTC
Permalink
Hi,

I have a scenario where I have sort orders in table for a given
SpecIDs. See below

SpecID SortOrder count
100110 1 6
100159 2 6
100025 3 6
100033 4 6
..... .... 6
.... 6 6

....... 1 12
..... 2 12
..... 3 12
... ... ...
.... 12 12

Now the above sort order need to be changed for the given SpecIDs. So
I need to update the sort order in the table based on the requirement.

As you see I need to update 6 records and 12 records to redefine the
sort orders. I am just thinking to write a script that updates the
table with 12+6 = 19 update statements in it. Is there any other way
to make it look professional?

Thanks,

L
Erland Sommarskog
2012-01-24 21:15:23 UTC
Permalink
Post by Learner
As you see I need to update 6 records and 12 records to redefine the
sort orders. I am just thinking to write a script that updates the
table with 12+6 = 19 update statements in it. Is there any other way
to make it look professional?
Maybe include

1) CREATE TABLE statemets for you tables
2) INSERT statements with sample data
3) The desired result given the sample
4) Which version of SQL Server you are using

would the question look more professional?

Good math would also increase the aura of professionalism.

On the other hand, with some copy-and-paste skills you would construct the
18 update statements while I'm typing this. Which, if this is a one-off,
definitely is as professional as it can get.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
Loading...