August 4, 2008 at 9:05 am
I need to caputure values from a column of varchar type which contains data both integer and string in varchar format. I need to pull data of integer type into new column alongwith NA for those rows whi9ch have no integer values. BUt the condition is that only 3 digit integer values should be displayed in new column and rest all values should be populated as NA.
I am using following code
select
case when
isNumeric(left([ParamValue],3)) = 1
then
left([ParamValue],3)
ELSE
stuff([ParamValue],1,len([ParamValue]),'NA')
END
as Status
from #temp
A sample of [ParamValue] is like:
[ID] [ParamValue]
1 11 days
2 21 days
3 Unable to resolve destination host address.
4 403
I need to populate like
[ID] [ParamValue] [New Column]
1 11 days NA
2 21 days NA
3 Unable to resolve destination host address. NA
4 403 403
I hope I am much clear with what I require. Can anyone help me out in getting this:
Thanks
Saurabh
August 4, 2008 at 11:56 am
I could be missing something, but it looks like what you posted will do what you need. Do you have a question about it, or a problem with it?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
August 4, 2008 at 12:00 pm
IS the new column DEFINED as INT? If so you can't put the value 'NA' in a integer column. In the case you would want to use NULL or some impossible numeric value and then have your UI code display 'NA' when NULL (or defined NA integer value).
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 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply