Thanks for your prompt reply,
I recieve an error:
Msg 402, Level 16, State 1, Procedure CommentsA, Line 7
The data types ntext and varchar are incompatible in the equal to operator.
Thanks
Main Topics
Browse All TopicsHi,
I've got myself a little confused,
part of my query is the following:
(isnull(cast(AStatus as varchar),'-')) and
(isnull(cast(AComments as varchar(max)),''))
I trying combine these these so if status is blank but comments is not blank add some text so if:
AStatus = "A" (or anything other than blank/null)
AComments = "Test"
then this should output just the "Test",
AStatus = ""
AComments = "Test"
then this should output just the "temp, Test"
AStatus = ""
AComments = ""
then this should output just the ""
Hope this makes sense and someone can help.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Ah, I ignored your casts - they were there for some good reasons, obviously ;-)
To mimic your original formula (I don't know if all casts are necessary, but according to the error message at least AComments needs to be casted):
case
when cast(isnull(AStatus, '') as varchar) = ''
and cast(isnull(AComments, '') as varchar(max)) = '' then ''
when cast(isnull(AStatus, '') as varchar) = '' then 'temp ' + cast(AComments as varchar(max))
else cast(AComments as varchar(max))
end
We could use some better (less redundant) expressions, but you have to change the select then.
Business Accounts
Answer for Membership
by: QlemoPosted on 2009-11-04 at 14:43:27ID: 25744882
case
when isnull(AStatus, '') = '' and isnull(AComments, '') = '' then ''
when isnull(AStatus, '') = '' then 'temp ' + AComments
else AComments
end