I have a column in my sql table that contains 2 different values, I would like to separate them into 2 different columns! How do I go about doing this? I'm a beginner to sql so my knowledge is very limited! Thanks in advance for your help!
Next, populate the new column and adjust the original/old column:
update <table>
set new_col = substring(old_col,charindex(old_col,'-')+1)
, old_col = substring(old_col,1,charindex(old_col,'-')-1)
; "Helping others to help themselves..."
=================================
Thomas V. Flaherty Jr.
Birch Hill Technology Group, Inc.
Remember I'm new to SQL so when you say to "populate the new column and adjust the original/old column" I'm not
really sure where I'm suppose to go or what to do. Can you give me detailed instructions Please?
** Substitute your actual table name for <table name>
** Substitute the column currently containing the data for "old_col"
** Substitute the newly added column for "new_col"
You would create the new column using Enterprise Manager (or ask a DBA if you have one).
You would run the UPDATE statement in Query Analyzer.
"Helping others to help themselves..."
=================================
Thomas V. Flaherty Jr.
Birch Hill Technology Group, Inc.
Sorry, the 3rd argument (length) is now required, my mistake. Also, I had the order of the argument backwards in the CHARINDEX functions...
update CallLog
set test= substring(cause,
charindex('-',cause)+1,
LEN(cause) - charindex('-',cause)
)
, cause = substring(cause,1,charindex('-',cause)-1)
;
"Helping others to help themselves..."
=================================
Thomas V. Flaherty Jr.
Birch Hill Technology Group, Inc.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.