Re: sqlexec() with multiple SQL commands

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Anders Altberg (x_pragma_at_telia.com)
Date: 11/01/04


Date: Mon, 1 Nov 2004 20:02:54 +0100

Hi Alan
This is how the original appears to me in Outlook Express

m_query = 'insert into table_a (field_a) values (100); select
@@identity;'

with a line break after the word select. That, as I see it, will not work
without a ; after the word select, like this:
m_query = 'insert into table_a (field_a) values (100); select ;
@@identity;'
The ; would be a VFP line continuation character. If his string is orginally
all in one line, then it's technically correct and should work.
If it doesn't work you can pick up the OSDB C error in AERROR(arrayname)
-Anders

"Alan C. Sheffield" <asheffield @ park west gallery.com> wrote in message
news:enn68TCwEHA.2196@TK2MSFTNGP14.phx.gbl...
> I understand the advantages to using the TEXT - ENDTEXT.
>
> The thing I am missing is the difference in the original SQL and what you
> posted. If the difference is not the pleasance of the line break, what
would
> make yours work and the original not work. I can not see where the
resulting
> string would be different.
>
> I know I have to have missed something.
>
> OR are you saying that the difference is in the construction of the string
> and I should not expect to see the difference but that SQL Server will?
>
> Alan
> "Anders Altberg" <x_pragma@telia.com> wrote in message
> news:eBRhrP6vEHA.200@TK2MSFTNGP11.phx.gbl...
> > Hi Alan
> > The advantage of using TEXT - ENDTEXT [NOSHOW} [TEXTMETRGE] for queries
> is
> > , as I see it, that you can get rid of all the quote character and + and
;
> > in a concatenated chain. Simpler to read, simpler to write, for yourself
> and
> > for future programmer revisiting the code. It also means you can copy
and
> > paste queries from textbooks, SQL Server samples or newsgroups without
> much
> > editing. Your queries will look exactly as a SQL Server programmer's
code
> > would.
> >
> > -Anders
> >
> > "Alan C. Sheffield" <asheffield @ park west gallery.com> wrote in
message
> > news:uvGMX7bvEHA.3612@TK2MSFTNGP09.phx.gbl...
> > > OK, I guess I messed something then. What's the effective difference
> > between
> > > Randy's original code and your example. I do not see that the result
> would
> > > be different other than the link breaks.
> > >
> > > Alan
> > >
> > > "Anders Altberg" <x_pragma@telia.com> wrote in message
> > > news:e2JpbRUvEHA.2520@TK2MSFTNGP15.phx.gbl...
> > > > You don't have to separate SQLServer commands on separate lines.
thew
> ;
> > > > shows is the end-of-command chrarcter. It's confusing of course that
> for
> > > VFP
> > > > the ; is a line continuation charachter and chr(1# is th end of
> command
> > > > this works in q query sent to SQLServer as a one-line string
> > > > lcSQL = [select * from customers; insert into customers (lastname)
> > values
> > > > ('x') ; delete from customers where lastname = 'x';]
> > > > or in VFP with 2 line breaks
> > > > lcSQL = [select * from customers; insert ;
> > > > into customers (lastname) ;
> > > > values ('x') ; delete ;
> > > > customers where lastname = 'x';]
> > > > SQLEXEC(h, lcsql)
> > > >
> > > > or using TEXT - ENDTEXT
> > > > TEXT TO lcSQL NOSHOW
> > > > select * from customers; insert into
> > > > customers (lastname) values ('x') ; delete
> > > > from customers where lastname = 'x';
> > > > ENDTEXT
> > > > SQLEXEC(h, lcSQL)
> > > >
> > > > -Anders
> > > >
> > > > "Alan C. Sheffield" <asheffield @ park west gallery.com> wrote in
> > message
> > > > news:e2Dm7pPvEHA.2616@TK2MSFTNGP10.phx.gbl...
> > > > > could you get the same result by just inserting a chr(13) into the
> sql
> > > > > string?
> > > > >
> > > > > m_query = 'insert into table_a (field_a) values (100);'
> > > > > +chr(13)+' select @@identity;'
> > > > >
> > > > > m_retcode = sqlexec(m_handle,m_query,"cursor10")
> > > > >
> > > > >
> > > > > Alan
> > > > > "Anders Altberg" <x_pragma@telia.com> wrote in message
> > > > > news:u2LjuI9tEHA.2192@TK2MSFTNGP14.phx.gbl...
> > > > > > Hi Randy
> > > > > > TEXT TO lcSQL NOSHOW
> > > > > > insert into table_a (field_a) values (100);
> > > > > > select
> > > > > > @@identity;
> > > > > > ENDTEXT
> > > > > > s=SQLEXEC(conn, lcSQL, 'retval')
> > > > > >
> > > > > > SQLServer will ignore the linbreaks in the text
> > > > > > -Anders
> > > > > >
> > > > > > <rmbyers@magma.ca> wrote in message
> > > > > > news:34b8n01jqdm65381n6ciklbqjvtgn936r0@4ax.com...
> > > > > > > Hello,
> > > > > > >
> > > > > > > I want to send two SQL commands to the SQL server with just
one
> > > > > > > SQLEXEC() call. I believe this should be possible, but it
> doesn't
> > > > > > > appear to work.
> > > > > > >
> > > > > > > Here is the code:
> > > > > > >
> > > > > > > m_query = 'insert into table_a (field_a) values (100); select
> > > > > > > @@identity;'
> > > > > > >
> > > > > > > m_retcode = sqlexec(m_handle,m_query,"cursor10")
> > > > > > >
> > > > > > >
> > > > > > > ** notice the semicolon separating the two SQL commands in
> m_query
> > > > > > >
> > > > > > > I would expect to get a cursor back containing a field named
> "exp"
> > > > > > > which would be the identity value for table_a (which has an
> > identity
> > > > > > > column named "id")
> > > > > > >
> > > > > > > Any ideas would be appreciated.
> > > > > > >
> > > > > > > Thanks
> > > > > > > Randy
> > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > >
> > >
> >
>
>



Relevant Pages

  • Re: Linking tables access - sql server 2005
    ... Another advantage of this method is that you don't need an ODBC setting on the local computer, ... Create a linked table to SQL Server without using a DSN ... Name of the table that you are linking to on the SQL Server database ... Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Cannot Generate SSPI Context - help
    ... I have used the following DSN-less string: ... Microsoft OLE DB Provider for SQL Server error '80004005' ... When a connection is "trusted," it means ... > How would one connect to a remote SQL Server using Windows authen? ...
    (microsoft.public.inetserver.asp.db)
  • Re: INSERT Query problem with Quotes & Apostrophes
    ... I've got front-ends that go against both Jet and SQL Server databases. ... InputText As String, _ ... >> Delimiter, Delimiter & Delimiter) ... dDateTime, ...
    (microsoft.public.access.modulesdaovba)
  • Re: ADO.NET 2.0 saving single space to SQL?
    ... It is code someone else wrote quite some time ago and all of the string ... Hitchhiker's Guide to Visual Studio and SQL Server ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: using OpenXML in T-sql?
    ... am not the most senior person in sql server programming, ... especially xml stuff. ... style string in place of an array without the additional ... >delimited strings and opts for the xml string instead. ...
    (microsoft.public.sqlserver.programming)