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

x
?
Solved

ISNULL value replacement , withing a string

Posted on 2011-10-20
8
Medium Priority
?
200 Views
Last Modified: 2012-05-12
Hi all
I looking for a way to replace a column
if the value is NULL with an alternate value

Since I need to assign the select statement to a variable..
The current formating I got, is not working see code below
declare 

@ErrorMessage varchar(25)
set @ErrorMessage = 'This is a  2248 Error'

SET @sql_trans_VProtokoll	 = ' SELECT i.EBILL as Transaction,SUBSTRING(h.zeichnung,1,15) as Zeichnung,
ISNULL(i.infoText, ''' + @ErrorMessage + ''') as ReasonText '

Open in new window

0
Comment
Question by:ZURINET
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 36998721
Check this modified query
declare @sql_trans_VProtokoll varchar(max)
declare @ErrorMessage varchar(25)
set @ErrorMessage = 'This is a  2248 Error'

SET @sql_trans_VProtokoll	 = ' SELECT i.EBILL as Transaction,SUBSTRING(h.zeichnung,1,15) as Zeichnung,
ISNULL(i.infoText, ''' + @ErrorMessage + ''') as ReasonText '

-- check the value
select @sql_trans_VProtokoll

Open in new window

0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 36998725
What error are you getting?
0
 

Author Comment

by:ZURINET
ID: 36999036
Hallo RajkumarGS

What is the difference between my code and yours?
My problem is that the msg @ErrorMessage = 'This is a  2248 Error'
is not returned..
The query is returning -- null



0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 25

Expert Comment

by:Lee Savidge
ID: 36999053
How have you defined @sql_trans_VProtokoll?
0
 
LVL 4

Expert Comment

by:qasim_md
ID: 36999146
Here is the solution

declare @ErrorMessage varchar(25)
declare @sql_trans_VProtokoll varchar(max)
set @ErrorMessage = 'This is a  2248 Error'

SET @sql_trans_VProtokoll       = ' SELECT i.EBILL as ''Transaction'',SUBSTRING(h.zeichnung,1,15) as Zeichnung,
ISNULL(i.infoText, ''' + @ErrorMessage + ''') as ReasonText '

print (@sql_trans_VProtokoll)
--exec (@sql_trans_VProtokoll)
0
 

Author Comment

by:ZURINET
ID: 36999242
Find where the problem lies...
The infoText is declared as sql data type text
and the value inside is NULL string.. and not null

Wondering how I can solve this now?
0
 
LVL 4

Accepted Solution

by:
qasim_md earned 1500 total points
ID: 36999306
I assume everything is alright your query is failing only because you have used Transaction Keyword in your as condition....

Replace that with the single quotes and it will work. Example:

declare @ErrorMessage varchar(25)
declare @sql_trans_VProtokoll varchar(max)
set @ErrorMessage = 'This is a  2248 Error'

SET @sql_trans_VProtokoll       = ' SELECT i.EBILL as ''Transaction'',SUBSTRING(h.zeichnung,1,15) as Zeichnung,
ISNULL(i.infoText, ''' + @ErrorMessage + ''') as ReasonText '

print (@sql_trans_VProtokoll)
0
 

Author Closing Comment

by:ZURINET
ID: 37005432
The problem lies in the data I have in the database
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

581 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