• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 43
  • Last Modified:

Need help declaring a variable to delete carriage returns

I have the following statement to delete carriage returns
  select replace(replace(NOTES, @cr, ''), @lf, '') from [CONV].[dbo].[tblServiceOrd]

Open in new window

but I keep receiving this error: Must declare the scalar variable "@cr". Any help will be appreciated.
0
maximus1974
Asked:
maximus1974
  • 2
2 Solutions
 
Mark WillsTopic AdvisorCommented:
In sql we dont have some of the built-in controls, so we must declare each variable first.
DECLARE @CR char(1) = char(13)
DECLARE @lf char(1) = char(10)

select replace(replace(NOTES, @cr, ''), @lf, '') from [CONV].[dbo].[tblServiceOrd]

Open in new window

Or better still, just use CHAR()
select replace(replace(NOTES, char(13), ''), char(10), '') from [CONV].[dbo].[tblServiceOrd]

Open in new window

0
 
Rgonzo1971Commented:
HI,

pls try
DECLARE @cr AS CHAR(1) = CHAR(13)
DECLARE @lf AS CHAR(1) = CHAR(10)
select replace(replace(NOTES, @cr, ''), @lf, '') from [CONV].[dbo].[tblServiceOrd]

Open in new window

Regards
0
 
Mark WillsTopic AdvisorCommented:
excuse me - how is that any different to my post ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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