April 12, 2011 at 6:24 pm
Hey Everyone,
basically i want something that looks at the 3rd letter from my unit column
,in this case will use '22CJe' and if It finds 'C' in the 3rd place from left
then it will return 'CONVENTIONAL' to a new column next to it.
Example: 22CJe
Returns:
22Cje | Conventional
If this doesn't make sense i can provide additional info.
April 12, 2011 at 8:05 pm
Lookup SUBSTRING and CASE in books online, here is an example:
SELECT ...
,t.unit
,CASE substring(t.unit, 3, 1)
WHEN 'C' THEN 'CONVENTIONAL'
ELSE 'NOT CONVENTIONAL'
END AS UnitType --???
FROM dbo.MyTable t
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
April 13, 2011 at 10:37 am
You can also use CHARINDEX();
IF OBJECT_ID(N'tempdb..#test', N'U') IS NOT NULL DROP TABLE #test;
CREATE TABLE #test(val VARCHAR(10));
INSERT INTO #test
(
val
)
SELECT
'22JCC'
UNION ALL
SELECT
'22CJe'
UNION ALL
SELECT
'2CCJe'
UNION ALL
SELECT
'CCAJe'
SELECT
val,
CASE WHEN CHARINDEX('C', val, 3) = 3 THEN 'Conventional'
ELSE 'Non Conventional'
END AS unit_type
FROM
#test
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
April 13, 2011 at 10:50 am
A short poem if I may:
Books have knowledge.
To apply knowledge is wisdom.
One must learn to apply this subtle truth,
by those that teach, who've climbed the mountain
of independent thinking.
--Thanks again.
April 13, 2011 at 11:28 am
Now if i could only figure out how to close this topic...
April 13, 2011 at 1:16 pm
Ricardumus (4/13/2011)
Now if i could only figure out how to close this topic...
There is no way to close topics on SSC. They stay open for eternity and sometimes 5 year old topics get new comments.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply