Solved

replace is null in all columns with a blank

Posted on 2010-08-31
15
477 Views
Last Modified: 2012-05-10
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
Comment
Question by:edo60
  • 4
  • 3
  • 2
  • +5
15 Comments
 
LVL 6

Accepted Solution

by:
apresence earned 500 total points
ID: 33570408
For Microsoft SQL Server:
ISNULL(curwages, 0) + ISNULL(curselfemployed, 0) + ISNULL(curtaxreturn, 0) AS wages
0
 
LVL 6

Expert Comment

by:apresence
ID: 33570416
Ignore that, posted answer to the wrong question
0
 
LVL 1

Expert Comment

by:rajmraji
ID: 33570465
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
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33570471
Your code works correctly for all records, do you mean all columns?
0
 

Author Comment

by:edo60
ID: 33570555
all columns that have nulls

thank you a lot
0
 
LVL 5

Expert Comment

by:almander
ID: 33570757
You do not really even need a where clause.
update ramales set  at12 =  IsNull(at12, ' ')

Open in new window

0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 33570786
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33570982
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
 
LVL 11

Expert Comment

by:Larissa T
ID: 33571826
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
 

Author Comment

by:edo60
ID: 33572835
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
 
LVL 4

Expert Comment

by:parthmalhan
ID: 33573915
Your Query is allright
0
 

Author Comment

by:edo60
ID: 33578972
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
 

Author Comment

by:edo60
ID: 33578976
is any way to fix it from the report?
tjhank you a lot
0
 
LVL 5

Expert Comment

by:almander
ID: 33579050
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
 
LVL 5

Expert Comment

by:almander
ID: 33579084
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now