473,473 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

isnull and ntext variables (short question)

Hello to all,

Below the sample code:

declare @arg_szMsgText ntext
set @arg_szMsgText = isnull(@arg_szMsgText, N'unknown message')

Now the error message I get:

"The assignment operator operation cannot take a ntext data type as an
argument."

Explanation:
I'm using it in a SP. I was trying thousand things to make it running,
and the only way I maked was, I get it when I set the return value from
isnull fucntion to nvarchar or varchar variable.
The problem is, the field in DB, where the value of @arg_szMsgText is
written) is ntext, so I need to use this format.

In the description of isnull function (help) is written:

----------------------------------------------------
Arguments
check_expression

Is the expression to be checked for NULL. check_expression can be of
any type.

replacement_value

Is the expression to be returned if check_expression is NULL.
replacement_value must have the same type as check_expresssion.

Return Types
Returns the same type as check_expression.

-----------------------------------------------------

so ite means, I should be able to use this in such a way ...

I know I can assign the value in other way (like by if @variable is
null ....), but if there is already function doing this, why not to use
it, if it helds the code more clear?

Any ideas? Maybe I'm doing something wrong.

Matik

Jul 23 '05 #1
3 8881

"Matik" <ma****@sauron.xo.pl> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hello to all,

Below the sample code:

declare @arg_szMsgText ntext
set @arg_szMsgText = isnull(@arg_szMsgText, N'unknown message')

Now the error message I get:

"The assignment operator operation cannot take a ntext data type as an
argument."


<snip>

I'm not sure where you're running those commands - I got the following (much
clearer) message using Query Analyzer:

Server: Msg 2739, Level 16, State 1, Line 1
The text, ntext, and image data types are invalid for local variables.

See DECLARE in Books Online - you can't declare an ntext variable, although
you can use ntext for stored procedure parameters. If you can give more
details of what you're trying to do, someone may have a suggestion on what
else you can do.

Simon
Jul 23 '05 #2
Hej Simon,

Thank you for your reply.

I'm using it in a stored procedure, as an input parameter, but then, I
need to insert it as a value of collumn into table.
Because the value passed by calling stored procedure can be null, I
need to avoid inserting null's into my table. That's why, I thought I
can jus use this simple function, to avoid carrying empty (null) data
value in this variable.

Any other ideas?

Matik

PS I get this message, when I try to alter my stored procedure...

Jul 23 '05 #3
Matik (ma****@sauron.xo.pl) writes:
Thank you for your reply.

I'm using it in a stored procedure, as an input parameter, but then, I
need to insert it as a value of collumn into table.
Because the value passed by calling stored procedure can be null, I
need to avoid inserting null's into my table. That's why, I thought I
can jus use this simple function, to avoid carrying empty (null) data
value in this variable.

Any other ideas?


INSERT tbl (.... ntextcol)
VALUES (.... isnull(@ntextpar, N'Unknown message')

or

INSERT tbl (.... ntextcol)
VALUES (.... coalesce(@ntextpar, N'Unknown message')

of if none of that works out:

if @nextpar IS NOT NULL
INSERT tbl (.... ntextcol)
VALUES (.... @ntextpar)
else
INSERT tbl (.... ntextcol)
VALUES (.... N'Unknown message')
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin | last post by:
Dear Group I admit, this might be a very ignorant question. BOL says about the ntext data type: Variable-length Unicode data with a maximum length of 2^30 - 1 (1,073,741,823) characters. ...
1
by: Derek Erb | last post by:
SQL Server 2000 : I have a series of tables which all have the same structure. When any of these tables are modified I need to syncrhonise all of those modifications with one other table wich is a...
2
by: Sileesh | last post by:
HI I know this is not the right forum to post this question, but i think some one might have a suggestion. I have a Table "Test" with columns Id bigint (PK), Number Varchar(50), Notes ntext....
4
by: Laphan | last post by:
Hi all In my functions I'm using a double-check all the time to trap if a value has nothing in it and my question is do I need this double-check. My check line is: IF IsNull(xxx) OR...
2
by: Igor | last post by:
Is there a way to transfer ntext data from one table to another? I tried this UPDATE SET = (SELECT FROM WHERE =1) WHERE = 1;
3
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
I try to follow Steve's paper to build a database, and store a small text file into SQL Server database and retrieve it later. Only difference between my table and Steve's table is that I use NTEXT...
2
by: verb13 | last post by:
I am running this query to an sql server 2000 database from my asp code: "select * from MyTable where MySqlServerRemoveStressFunction(MyNtextColumn) = '" & MyAdoRemoveStressFunction(MyString) &...
1
by: ozmodius | last post by:
hey guys, I'm a complete noob when it comes to SQL, thanks for any help you can give. the folowing query wants me to group by fields that are Ntext and this can't happen. any suggestions? ...
1
by: balamk81 | last post by:
I've a question about ntext and text. How do you use them in a stored procedure? When I try to use an ntext data type in a proc i get this error - 'The assignment operator operation cannot take a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.