Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Modify statement to run sp_executesql
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
aspfun  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 13:42
Newsgroups: microsoft.public.sqlserver.programming
From: "aspfun" <u53138@uwe>
Date: Sat, 07 Nov 2009 13:42:35 GMT
Local: Sat 7 Nov 2009 13:42
Subject: Modify statement to run sp_executesql
To learn sp_executesql, I create a small code. It works fine as below.

CREATE TABLE [dbo].[#A](
        [authno] [nchar](10) NULL,
        [Authname] [nvarchar](50) NULL
) ON [PRIMARY]

INSERT INTO #A (AUTHNO, AUTHNAME)
VALUES('444' + '~', 'EEE')

Once run sp_executesq, got an error said

Incorrect syntax near '444'. How to fix it?

CREATE TABLE [dbo].[#A](
        [authno] [nchar](10) NULL,
        [Authname] [nvarchar](50) NULL
) ON [PRIMARY]

DECLARE @sql nvarchar(200)
set @sql = N'
INSERT INTO #A (AUTHNO, AUTHNAME)
VALUES('444' + '~', 'EEE')'
exec sp_executesql @sql


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Farmer  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 14:56
Newsgroups: microsoft.public.sqlserver.programming
From: "Farmer" <some...@somewhere.com>
Date: Sat, 7 Nov 2009 09:56:26 -0500
Local: Sat 7 Nov 2009 14:56
Subject: Re: Modify statement to run sp_executesql
How about this

DECLARE @sql nvarchar(200)
set @sql = N'
INSERT INTO #A (AUTHNO, AUTHNAME)
VALUES(''444'' + ''~'', ''EEE'')'
exec sp_executesql @sql


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erland Sommarskog  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 17:53
Newsgroups: microsoft.public.sqlserver.programming
From: Erland Sommarskog <esq...@sommarskog.se>
Date: Sat, 7 Nov 2009 17:53:56 +0000 (UTC)
Local: Sat 7 Nov 2009 17:53
Subject: Re: Modify statement to run sp_executesql

aspfun (u53138@uwe) writes:
> To learn sp_executesql, I create a small code. It works fine as below.

> CREATE TABLE [dbo].[#A](
>      [authno] [nchar](10) NULL,
>      [Authname] [nvarchar](50) NULL
> ) ON [PRIMARY]

> INSERT INTO #A (AUTHNO, AUTHNAME)
> VALUES('444' + '~', 'EEE')

> Once run sp_executesq, got an error said

> Incorrect syntax near '444'. How to fix it?

Dynamic SQL is an advanced feature, and if you feel obliged to ask this
question, you should probably defer working with dynamic SQL, until you
master the basics better.

That said, I have an article on my web site, which covers dynamic SQL
in depth: http://www.sommarskog.se/dynamic_sql.html.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Bell  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 20:45
Newsgroups: microsoft.public.sqlserver.programming
From: "John Bell" <jbellnewspo...@hotmail.com>
Date: Sat, 7 Nov 2009 20:45:30 -0000
Local: Sat 7 Nov 2009 20:45
Subject: Re: Modify statement to run sp_executesql
To expand on this, when you need a quote in a string it has to be escaped
with another single quote.

John

"Farmer" <some...@somewhere.com> wrote in message

news:eaZl7p7XKHA.3612@TK2MSFTNGP02.phx.gbl...


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google