Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 486
  • Last Modified:

replace is null in all columns with a blank

i need a sql sentence for remove all is null with a ' '

like this
update ramales set at12=' ' where at12 is null

but all at once

is that posible??
thank you experts

0
Ernesto
Asked:
Ernesto
  • 4
  • 3
  • 2
  • +5
1 Solution
 
apresenceCommented:
For Microsoft SQL Server:
ISNULL(curwages, 0) + ISNULL(curselfemployed, 0) + ISNULL(curtaxreturn, 0) AS wages
0
 
apresenceCommented:
Ignore that, posted answer to the wrong question
0
 
rajmrajiCommented:
the only way i can think  of is to write a query that gets you all the columns in your tables (loking at the syscolumns, systables, etc) and build a dynamicall executed series of string that do what you have above to each column...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
cyberkiwiCommented:
Your code works correctly for all records, do you mean all columns?
0
 
ErnestoAuthor Commented:
all columns that have nulls

thank you a lot
0
 
almanderCommented:
You do not really even need a where clause.
update ramales set  at12 =  IsNull(at12, ' ')

Open in new window

0
 
Scott PletcherSenior DBACommented:
UPDATE ramales
SET at12 = CASE WHEN at12 IS NULL THEN ' ' ELSE at12 END,
       otherCol01 = CASE WHEN otherCol01 IS NULL THEN ' ' ELSE otherCol01 END,
       otherCol02 = CASE WHEN otherCol02 IS NULL THEN ' ' ELSE otherCol02 END,
       otherCol03 = CASE WHEN otherCol03 IS NULL THEN ' ' ELSE otherCol03 END,
      --...
       otherCol30 = CASE WHEN otherCol30 IS NULL THEN ' ' ELSE otherCol30 END
WHERE at12 IS NULL
    OR otherCol01 IS NULL
    OR otherCol02 IS NULL
    OR otherCol03 IS NULL
    --....
    OR otherCol30 IS NULL
0
 
cyberkiwiCommented:
update ramales set
at12=coalesce(at12, ' '),
at13=coalesce(at13, ' '),
at14=coalesce(at14, ' '),
at21=coalesce(at21, ' '),
at22=coalesce(at22, ' ')


List your columns using this pattern.
0
 
Lara FEACommented:
Why you don't like nulls? They are useful...

This select will produce update statements for all nullable columns in your database. Add other datatypes as needed
copy printed statement and  and execute in sql.
Use "where" in updates if you can. Without where It will produce many more transaction in you transaction log and will run longer

select t.name, c.name,
'update '+ t.name +' set '+c.name+'='''' where '+c.name+' is null '
from sysobjects t
join syscolumns c on t.id = c.id
join systypes ty on c.xtype=ty.xtype
where t.type = 'U' and t.status > 0 and ty.name in ('char','nchar','nvarchar','varchar') and isnullable = 1
order by t.name, c.name
0
 
ErnestoAuthor Commented:
i know there are usefulls
but in a sql command in crystal reports 8
do not put me all the string if one of the values is null
then i need blanks for acomplish this task of display a string in crystal reports

thank you a lot
0
 
parthmalhanCommented:
Your Query is allright
0
 
ErnestoAuthor Commented:
its right , but when find a null in the string
do not display
is this

(select("a48"+"a42"+"a36"+"a30"+"a24"+"a20"+"a18"+"a16")
from ramales
where (pos=8)and (proyecto="Proyectotmp"."Proyecto")and (spec="paso"."spec")
)
0
 
ErnestoAuthor Commented:
is any way to fix it from the report?
tjhank you a lot
0
 
almanderCommented:
In my opinion, it is best to create a view, and access that view in crystal. Handling nulls in Crystal can get quite cumbersome. Not to mention that if it encounters a null, it stops processing a statement.

I would create a view similar to below to handle the nulls. And map to the view in crystal.
select IsNull(a48,'')+IsNull(a42,'')+IsNull(a36,'')+IsNull(a30,'')+IsNull(a24,'')+IsNull(a20,'')+IsNull(a18,'')+IsNull(a16,'') AS YOUR_FIELD_NAME
from ramales 

Open in new window

0
 
almanderCommented:
To fix this in the report you should select the columns individually.

SELECT a48, a42, a36
etc...

Then create a formula to concatenate the string, testing nulls.

IIF(IsNull({a48}), "", {a48}) + IIF(IsNull({a48}), "", {a42}) + IIF(IsNull({a48}), "", {a36})
etc...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now