[Webinar] Streamline your web hosting managementRegister Today

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

ISNULL(@variable,'') returns NULL on one server, empty string on another

A query

DECLARE
      @state_code            varchar(2)
 
SELECT @state_code = ''

DECLARE @state_def varchar(30)
      
SELECT @state_def  =  ISNULL(definition,'')
FROM cd_states
WHERE state_code = @state_code

SELECT @state_def  


@state_def   returns NULL on one server and empty string on another.

User options as defined by @@OPTIONS are the same. No ANSI connection settings change.
SQL 2005 compatibility

0
robertkray
Asked:
robertkray
1 Solution
 
Brian CroweDatabase AdministratorCommented:
If there is no record in cd_states where state_code = @state_code then there are no records found and hence the ISNULL function is never called.

try...


SELECT @state_def  =  definition
FROM cd_states
WHERE state_code = @state_code

SELECT ISNULL(@state_def, '')
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now