SAP Knowledge Base Article - Preview

2965936 - How to write a stored procedure using a variable where quotes are required - SAP ASE

Symptom

  • Creating a stored procedure or / adhoc query which requires a variable to be used inside quotes. 
  • Example:

declare @name varchar(20)
declare @combine varchar(40)
declare @dirname varchar(20)
select @dirname = "/tmp"
select @name = (select user_name())
select @combine = @dirname + "/" + @name + "/"
set statistics plan_directory_html @combine

The results show:

Msg 102, Level 15, State 181:
Server 'myserver', Line 8:
Incorrect syntax near '@combine'.

  • Example2:

declare @name varchar(20)
declare @combine varchar(40)
declare @dirname varchar(20)
select @dirname = "/tmp"
select @name = (select user_name())
select @combine = @dirname + "/" + @name + "/"
print "How to print the name @combine"

The results show:

How to print the name @combine

  • How can it be coded so that results are what is needed? Expecting "/tmp/user/" not @combine


Read more...

Environment

SAP Adaptive Server Enterprise (all versions)

Keywords

passing using variables incorrect results not expected wrong different , KBA , BC-SYB-ASE , Sybase ASE Database Platform (non Business Suite) , How To

About this page

This is a preview of a SAP Knowledge Base Article. Click more to access the full version on SAP for Me (Login required).

Search for additional results

Visit SAP Support Portal's SAP Notes and KBA Search.