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
 General SQL Server Forums
 New to SQL Server Programming
 Substring and concatenate
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/05/2012 :  11:14:01  Show Profile  Reply with Quote
i need to populate the County column in my GCSOSubjects table with a substring of the COURTNAME field in that same table. The values in COURTNAME are all formatted as "COUNTY-LEON" or "COUNTY-GADSDEN", or "CIRCUIT-GADSDEN" or "COUNTY-GADSDEN". The data is always either CIRCUIT-something or COUNTY-something.

My instinct (as poor as it is) is to populate COUNTY using a substring with a where / like clause, but i'm not sure about the values for the substring. For instance, using:


Update GCSOSUBJECTS set COUNTY=SUBSTRING(COURTNAME,8,?) where COURTNAME LIKE 'COUNTY-%'

Update GCSOSUBJECTS set COUNTY=SUBSTRING(COURTNAME,9,?) where COURNTNAME LIKE 'CIRCUIT-%'


My uncertainty is the second numerical value of the substring for each update.

Of course, i'm sure someone is going to tell me there is a completely "other" way to do this not involving anything i'm attempting here. At any rate, anything that works.

thanks

james

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/05/2012 :  11:19:21  Show Profile  Reply with Quote
Sorry, and "concatenate" should not have been in the title of this one. That was from another issue rolling around in my brainpan.
Go to Top of Page

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/05/2012 :  11:35:26  Show Profile  Reply with Quote
Disregard. figured it out.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48094 Posts

Posted - 04/05/2012 :  11:45:39  Show Profile  Reply with Quote
can you post solutions for others understanding?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/05/2012 :  12:25:19  Show Profile  Reply with Quote
Basically, in using this process, i used a numerical value for the second part of the substring which was longer than the len of any of the rows in that table. So my queries wound up looking like:


Update GCSOSUBJECTS set COUNTY=SUBSTRING(COURTNAME,8,20) where COURTNAME LIKE 'COUNTY-%'

Update GCSOSUBJECTS set COUNTY=SUBSTRING(COURTNAME,9,20) where COURNTNAME LIKE 'CIRCUIT-%'

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.06 seconds. Powered By: Snitz Forums 2000