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 2005 Forums
 Transact-SQL (2005)
 Dynamic table update

Author  Topic 

direrayne
Starting Member

30 Posts

Posted - 2011-01-31 : 10:19:09
I have a table that i need to replicate data in certain rows.
example:

ship code class target
carnival 3 4 20
navigator 2 3 20
canival 6 7 NULL

Because of the number of rows and the number of ships i need to write a code that will find a ship and taget then find the emtpy targets and full them in dynamically.

Jim Beam
Posting Yak Master

137 Posts

Posted - 2011-02-01 : 14:54:24
This is just a start, as I've got not one, but TWO bits of bad news for ya....

1) I'm in the process of learning myself (yeah, I know my status reads "Master", just don't believe everything you read!), but want to try;

2) You don't mention what values the target field needs to have, as I imagine they will differ between the good ships Navigator and 'Carnival', and even when you do, that will need more skill in 'When...Then' clauses than I currently have.

That said, best of luck to you, and here we go...

@ship
@target

Update YourTableNameHere
Set Target = 'YourDesiredTargetValueHere'
Where YourTableNameHere.Target is Null
And YourTableNameHere.Ship = @ship
And YourTableNameHere.Target = @target
Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-02-01 : 15:52:44
"A problem well stated is a problem half solved." -- Charles F. Kettering

Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. If you know how, follow ISO-11179 data element naming conventions and formatting rules. Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.

Sample data is also a good idea, along with clear specifications. It is very hard to debug code when you do not let us see it. If you want to learn how to ask a question on a Newsgroup, look at: http://www.catb.org/~esr/faqs/smart-questions.html


--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page
   

- Advertisement -