Start Free Trial
Come for the solution, stay for everything else.
Start Free Trial
How can I copy a SQL column to another column and ignore nulls?
I need to copy all of the contents from one column to another. I'm running into an issue with the one that I'm using because there are nulls in the column that I am copying the data from.
Microsoft SQL Server 2008
8/22/2022 - Mon
SET some_column = some_other_column
>I'm running into an issue with the one that I'm using because there are nulls in the column
So ... what's the issue? If some_column is set to NOT NULL, then you can use ISNULL() to convert them to some other value
SET some_column = ISNULL(some_other_column, '')
The new column is set to null, but when I run the same command that you mention I get:
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
ASKER CERTIFIED SOLUTION
Log in or sign up to see answer
Become an EE member today
7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
I was able to accomplish what I needed done by using
SET date = CAST([field2] AS DATE)
WHERE ISDATE([field2]) = 1
Thanks for your help.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
Thanks for the grade. Good luck with your project. -Jim
Plans and Pricing
Certified Expert Program
© 1996-2022 Experts Exchange, LLC. All rights reserved. Covered by US Patent