Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

how to update table

$
0
0

Environment: SQL Server 2008 R2
Intro: StagingTable consists of three fields:  order_dt, SSN, Score. I also have another database object called dbo.badData which has the following order_dt , SSN, score, flagdata
Problem: After identifying and flagging the data in the stagingTable, I failed to move or update the data in the badData table. I really dont want to use temp tables and use if statement if the object_id exists  drop table. I ran into many issues and I like to use an update statment where I update the table in the baddata and delete the invalid from the staging table for other uses.

Code:

select 
order_dt, SSN, Score, 

CASE WHEN ISDATE(order_dt) = 0 THEN 'Invalid date' 
WHEN SSN like '%[^0-9]%' THEN 'Alphanumeric SSN'
WHEN ssn = '' OR ssn is null THEN 'BLANK SSN'
WHEN LEN(SSN)>9 THEN 'Invalid SSN'
WHEN order_dt >= getdate() THEN 'Date Leap'
When score is null THEN 'Invalid score'
ELSE 'VALID' END as [FlagStatus]

from StagingTable 



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>