Re: How to validate a query?
From: Stefan Delmarco [MSFT] (StefanDe_at_online.microsoft.com)
Date: 03/19/04
- Next message: David Lloyd-Williams: "Latest data for many objects"
- Previous message: Tibor Karaszi: "Re: Mysterious Port of SQL Server not shown by netstat"
- In reply to: Stefan Delmarco [MSFT]: "Re: How to validate a query?"
- Next in thread: Paul Reed: "Re: How to validate a query?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 19 Mar 2004 08:39:38 -0000
One thing to watch out for is that the SETs have to be in their own batch,
otherwise you won't get the behaviour you expect. That is, execute the SET
NOEXEC ON, then submit your TSQL, then SET NOEXEC OFF. If you submit your
TSQL and the SET NOEXEC in a single batch, your TSQL will actually be
executed. The SET NOEXEC only takes effect in the next batch.
Cheers,
Stefan
-- This posting is provided "AS IS" with no warranties, and confers no rights. "Stefan Delmarco [MSFT]" <StefanDe@online.microsoft.com> wrote in message news:e5SUkkYDEHA.2564@TK2MSFTNGP11.phx.gbl... > Hi Paul, have a look at SET NOEXEC in BOL: > > <Snip> > SET NOEXEC > Compiles each query but does not execute it. > ... > This setting is useful for having SQL Server validate the syntax and object > names in Transact-SQL code when executing. It is also useful for debugging > statements that would usually be part of a larger batch of statements. > </Snip> > > Also have a look at SET PARSEONLY in BOL: > > <Snip> > SET PARSEONLY > Checks the syntax of each Transact-SQL statement and returns any error > messages without compiling or executing the statement. > </Snip> > > (If you profile SQL when selecting "Check Syntax" in EM's SP Properities > window you'll that it uses NOEXEC and PARSEONLY to check the syntax without > actually creating the SP or executing the actual SQL). > > Cheers, > Stefan > > -- > This posting is provided "AS IS" with no warranties, and confers no rights. > > "paul reed" <prreed@jacksonreed.com> wrote in message > news:eHK$JRXDEHA.2908@TK2MSFTNGP09.phx.gbl... > > Hello, > > > > I have built a dynamic query builder for a project I am on. The user picks > > various fields they want retrieved and where criteria and the end result > is > > a query string that I build (much like what the query designer does in > EM). > > However, one property of my object is to return back a boolean whether or > > not the query I built is in fact valid (e.g., not only well-formed SQL but > > that it would execute if I tried to use it). What is the best way to do > > this? I know how to pass this string to a sproc and dynamically execute > > it...but I'd rather not have to execute the query to find out if it is > > valid. Is there any type of syntax check sproc that I can pass it to? > > > > Thanks in advance, > > > > Paul > > > > > >
- Next message: David Lloyd-Williams: "Latest data for many objects"
- Previous message: Tibor Karaszi: "Re: Mysterious Port of SQL Server not shown by netstat"
- In reply to: Stefan Delmarco [MSFT]: "Re: How to validate a query?"
- Next in thread: Paul Reed: "Re: How to validate a query?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|