STORED PROCEDURE SYNTAX ERROR

0 pts.
Tags:
Desktops
Management
Microsoft Windows
OS
Security
Servers
SQL Server
Please help, I would appreciate it. Below I have a simple stored procedure to return the names of my databases. I am getting a syntax error: Msg 105, Level 15, State 1, Line 1 Unclosed quotation mark before the character string 'PASBA-DEV '. Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'SERVER1-DEV Some of my server names contain hyphens, thus the reason for using [ ]'s in the procedure. Code for procedure begins here: ALTER PROCEDURE [dbo].[usp_getdatabasenames] @ServerName char(50) AS Declare @string2sql char(50) Set @string2sql = 'Select name from ['+@ServerName+'].[master].dbo.sysdatabases order by name'; EXECUTE (@string2sql)
ASKED: September 29, 2006  9:18 AM
UPDATED: September 29, 2006  10:21 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

At a quick glance your @server is Char(50) you @string is Char(50) your string is larger than 50 since you are using char instaead of varchar

Change both to varchar and also increase your @string to allow for all characters.

HTH,
Joe

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Bjack8468
    Thanks to jaylou, my problems are solved. Whoyaa!
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following