SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to update table from column to column in table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 12/27/2012 :  11:23:48  Show Profile  Reply with Quote
hello all,

i have a table in which i have 2 columns code and description

in first column i have data like
1 - Prevention
2 - Respiratory
3 - Cardiovascular

in 2nd column

NULL
NULL
NULL

i need to update

only Prevention,
Respiratory,
Cardiovascular

into 2 nd column

i have written query like this :

update ECT_HEDIS_SubDomain set SubDomainDescription = b.SubDomainDescription
from ECT_HEDIS_SubDomain b
INNER JOIN ECT_HEDIS_SubDomain a
on substring(a.ECTSubDomainCode,1,4) = b.ECTSubDomainCode

suggest me

P.V.P.MOhan

djj55
Constraint Violating Yak Guru

USA
336 Posts

Posted - 12/27/2012 :  11:33:51  Show Profile  Reply with Quote
Please check your example code as it looks like you are joining the table to itself. Also this will only update where ECTSubDomainCode is four characters or less.
Go to Top of Page

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/27/2012 :  11:48:58  Show Profile  Reply with Quote
Shouldn't it be like this

update ECT_HEDIS_SubDomain 
set ECTSubDomainCode = left(ECTSubDomainCode,Charindex(' - ',ECTSubDomainCode)-1) 
    SubDomainDescription = Substring(ECTSubDomainCode,Charindex('-',ECTSubDomainCode) + 2,len(ECTSubDomainCode))
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000