Solved

T-SQL string help

Posted on 2011-09-28
4
242 Views
Last Modified: 2012-05-12
We have a horrible table that I have adopted where the data type is nvarchar.. The data is supposed to look like 99 in the Grade2 column and most of it does but some records have $99,$110,$299.. ALL THREE plus $.. So basically this is what I want to do.. IF the record has $99,$110,$299 in Grade2  I want to put the 99 in a new column called Grade1 and leave 110 in the column called Grade2 and drop the third value $299.. I only want to do this if the column called Desc is not null.. I know this will be a Case Select I think? I have attached a spreadsheet as an example.. Tab1 shows what it currently looks like and Tab2 shows what I want. How do I do this?
Example.xls
0
Comment
Question by:cheryl9063
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 36742197
update yourtable
set grade1=99
    ,grade2=110
where grade2 ='$99,$110,$299'
AND DESC IS NOT NULL
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 36742640
SORRY

update yourtable
set grade1='99'
    ,grade2='110'
where grade2 ='$99,$110,$299'
AND DESC IS NOT NULL
0
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 500 total points
ID: 36746637
or where you wanting this?

update yourtable
set grade1=substring(grade2,2,charindex(',',grade2)-2)
  ,grade2=substring(grade2,charindex(',',grade2)+3,charindex(',',grade2,charindex(',',grade2,2)+1)-charindex(',',grade2)-2)
where grade2 like '$%,$%,%'
and desc is not null
0
 
LVL 1

Author Closing Comment

by:cheryl9063
ID: 36905022
Thanks!!!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Powershell finalizing the end of an array. 4 24
SQL QUERY 3 33
Can I skip a node in XML? 9 35
How come this XML node is not read? 3 31
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question