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)
 isnull help

Author  Topic 

kirank
Yak Posting Veteran

58 Posts

Posted - 2010-08-17 : 08:22:22


UPDATE E
SET E.bid = (SELECT TOP 1 IntBd FROM TblB WHERE ltrim(rtrim(BName)) like LTRIM(RTRIM(E.[BName]))+'%')

FROM #TmpFile E


hi on the above update how i can insert 0 values instead of null
on #TmpFile table (temp) how i can set 0
can i use

select CASE WHEN ISNULL((SELECT TOP 1 IntBd FROM TblB WHERE ltrim(rtrim(BName)) like LTRIM(RTRIM(E.[BName]))+'%'),0)

but it give me an error , whn above query(inner) will not return any records

if i try
select isnull(null,0) it return 0 but why not in my query
how i can madify it
help me

Kristen
Test

22859 Posts

Posted - 2010-08-17 : 08:30:09
select CASE WHEN ISNULL((SELECT TOP 1 IntBd FROM TblB WHERE ltrim(rtrim(BName)) like LTRIM(RTRIM(E.[BName]))+'%'),0)

should do the trick
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-17 : 09:13:48
Top 1 without order by doesn't make use. Consider using min/max value of column. If you want random value use same method you used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-17 : 10:28:42
[code]
UPDATE E
SET E.bid = B.IntBd

FROM #TmpFile E
OUTER APPLY(SELECT TOP 1 IntBd FROM TblB WHERE ltrim(rtrim(BName)) like LTRIM(RTRIM(E.[BName]))+'%' ORDER BY PK)B
[/code]

PK is primary key of TblB

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -