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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 hi, got a simple question

Author  Topic 

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-05-20 : 02:12:04
hi....i have been using
CAST(@a as char(10))
as the replacement of RPAD in oracle...is there any possible to print out null value of @a??

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-20 : 02:14:59
you can't print out a NULL value. NULL is unknown

if @a is null
begin
print '@a is null'
end



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-05-20 : 02:18:42
aiks, i been doing that...nvm...thx alot...^^
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-05-21 : 03:39:03
if @a is null
begin
print '@a is null'
end
is there anyway to print all column NULL instead of check each column?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-21 : 04:45:24
you mean this ?

select isnull(somecol, 'this is a null column')
from yourtable

provided that your col is a string datatype


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-05-21 : 05:02:32
erm i mean...sometime in table there are some column of data are NULL value
instead of checking every column, like
if @column1 IS NULL
set @column1 = ' '
is there any more general way to continue print

print cast(@column1 as char(10))

Result
*NULL value*

coz is there is any null value in that line, whole line data will gone missing
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-21 : 06:15:36
quote:
coz is there is any null value in that line, whole line data will gone missing

what do you mean by that ? are you concatenate this column with other columns ? you can use isnull() to return empty string when it null
example

isnull(column1, '') + isnull(column2, '') + isnull(column3, '')



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jholovacs
Posting Yak Master

163 Posts

Posted - 2009-05-21 : 10:25:33
how about this?

print cast(isnull(@column1, '') as char(10))




SELECT TOP 1
w.[name]
FROM
dbo.women w
INNER JOIN
dbo.inlaws i
ON
i.inlaw_id = w.parent_id
WHERE
i.net_worth > 10000000
AND
i.status IN ('dead', 'dying')
AND
w.husband_id IS NULL
ORDER BY
w.hotness_factor DESC
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-05-22 : 00:27:40
erm..i mean that is anything like a detecting null and change the null value to '-'
like it will detect every print job and when it found NUll, it will change to '-'
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-22 : 00:30:33
quote:
Originally posted by waterduck

erm..i mean that is anything like a detecting null and change the null value to '-'
like it will detect every print job and when it found NUll, it will change to '-'



You have to do it for every column where there is a possibility of NULL value using ISNULL() or COALESCE() or CASE statement


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-05-22 : 03:10:52
>"< too bad....
Go to Top of Page
   

- Advertisement -