Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
stahorse
Yak Posting Veteran
86 Posts |
Posted - 2013-07-03 : 04:25:35
|
HiI am selecting values to one table and populating them in another table, and I'm using a case statement to check if the word is the string 'NULL' then I replace it with value null.e.g CASE WHEN [Gross_Amount] = 'NULL' THEN NULL ELSE CAST([Gross_Amount] AS DECIMAL(18,2)) END[Gross_Amount]So I'm thinking I can write a function that can check to see the value if it is a string NULL, if so replace it with null or return Gross_Amount if not. and rewrite that whole CASE statement, to objective here is to minimise the lines of code.Can anyone help please. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-03 : 04:31:45
|
no need. better to keep it inline rather than making it a scalar UDF as scalr UDFs used over larger datasets can cause performance issues as they'll get expanded and executed once for each row in resultsetif you want you can simplify case when expression as followsNULLIF([Gross_Amount],'NULL')------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
stahorse
Yak Posting Veteran
86 Posts |
Posted - 2013-07-03 : 05:05:13
|
Thank youI actually thought of that, firstly it gave me a problem then I'm getting something wrong, finally got it though CAST(NULLIF([Gross Amount],'NULL') AS DECIMAL(18,2)) [Gross Amount] |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-03 : 05:08:20
|
Ok...Cool------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|