Groups | Blog | Home
all groups > sql server programming > february 2004 >

sql server programming : Need to UPDATE while conditions change...



Trint Smith
2/27/2004 10:19:04 PM
Ok, I need to start reading from the beginning of a table. 2 conditions:
While reading, if an endingdate column is less than todays date and
another columns value is "y" I need to copy data from one field to
another.
This must all be done from within vb.net.
Any help is appreciated.
Thanks,
Trint

.Net programmer
trintsmith@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
oj
2/27/2004 10:34:09 PM
Read the data into a dataTable or even a HashTable and then reopen the
connection and update.

--
-oj
http://www.rac4sql.net


[quoted text, click to view]

David Portas
2/28/2004 8:38:12 AM
UPDATE SomeTable
SET col1 = col2
WHERE endingdate < CONVERT(CHAR(8),CURRENT_TIMESTAMP,112)
AND other_col = 'y'

[quoted text, click to view]

Tables have no logical beginning or end. The set-based logic is "update the
set of rows where EndingDate is less than today's date and Other_Col = 'y'
".

--
David Portas
SQL Server MVP
--

Joe Celko
2/28/2004 10:49:05 AM
[quoted text, click to view]
While reading, if an endingdate column is less than todays date and
another column's value is "y" I need to copy data from one field [sic]
to another.<<

You need to read a book on SQL and RDBMS. Rows are not records; fields
are not columns; tables are not files; there is no sequential access or
ordering in an RDBMS, so "first", "next" and "last" are totally
meaningless.

Writing with flags and copying the same data into multiple places is
also a sign of bad program. About 99% of the time, it means that you
are doing procedural file processing in SQL and have completely missed a
set-oritned solution.

--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button