troubleshooting Question

Cast VARCHAR as INT keeping NULLs and setting text value to number

Avatar of ttist25
ttist25 asked on
Microsoft SQL ServerSQL
3 Comments1 Solution90 ViewsLast Modified:
Good morning,

I'm creating an int field from a varchar field in a staging table in SQL Server 2012.  

The field contains NULL values, positive and negative integers, and the text value "Unknown".

I would like to create a new int field and update it with the numeric values, set the text value of "Unknown" to 88888 and keep the NULL values as NULL.

I "tried" TRY_CAST but I really need the text "Unknown" set to the 88888 value because in this instance "Unknown" has a different meaning than NULL.  

Any help will be greatly appreciated.

Thanks!
ASKER CERTIFIED SOLUTION
ste5an
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros