September 8, 2014 at 7:57 am
Is it possible to pass entire where sentence to a store procedure?
From app, I'll generate a where sentence like below:
where orderID = '123' and orderCidy='London'
I created a store procedure like below but got an error said that
An expression of non-boolean type specified in a context where a condition is expected, near 'END'
CREATE PROCEDURE getorder
@mywhere VARCHAR(100)
AS
BEGIN
SET NOCOUNT ON;
select * from order @mywhere
END
September 8, 2014 at 8:00 am
Yes, but it requires dynamic SQL which means you're at risk of SQL Injection attacks.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 8, 2014 at 12:42 pm
adonetok (9/8/2014)
Is it possible to pass entire where sentence to a store procedure?From app, I'll generate a where sentence like below:
where orderID = '123' and orderCidy='London'
I created a store procedure like below but got an error said that
An expression of non-boolean type specified in a context where a condition is expected, near 'END'
CREATE PROCEDURE getorder
@mywhere VARCHAR(100)
AS
BEGIN
SET NOCOUNT ON;
select * from order @mywhere
END
Gail missed a great chance to toot her own horn. Take a look at the following article. The method Gail uses not only allows for the dynamic SQL that you're looking for but is also great for "catch all queries" (very similar in nature to your query) and it's all done without any chance of SQL Injection.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 8, 2014 at 1:04 pm
Jeff Moden (9/8/2014)
adonetok (9/8/2014)
Is it possible to pass entire where sentence to a store procedure?From app, I'll generate a where sentence like below:
where orderID = '123' and orderCidy='London'
I created a store procedure like below but got an error said that
An expression of non-boolean type specified in a context where a condition is expected, near 'END'
CREATE PROCEDURE getorder
@mywhere VARCHAR(100)
AS
BEGIN
SET NOCOUNT ON;
select * from order @mywhere
END
Gail missed a great chance to toot her own horn. Take a look at the following article. The method Gail uses not only allows for the dynamic SQL that you're looking for but is also great for "catch all queries" (very similar in nature to your query) and it's all done without any chance of SQL Injection.
Giving Jeff the assist (the link to the article):
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/[/url]
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
September 8, 2014 at 1:11 pm
As mentioned before, this can be an injection attack surface if not done properly, normally far more fail there than succeed. Look first at other alternatives like Gail's "catch all", if that's not what you need then please come back and we'll advice further.
😎
September 9, 2014 at 7:02 am
September 9, 2014 at 9:00 am
Matt Miller (#4) (9/8/2014)
Jeff Moden (9/8/2014)
adonetok (9/8/2014)
Is it possible to pass entire where sentence to a store procedure?From app, I'll generate a where sentence like below:
where orderID = '123' and orderCidy='London'
I created a store procedure like below but got an error said that
An expression of non-boolean type specified in a context where a condition is expected, near 'END'
CREATE PROCEDURE getorder
@mywhere VARCHAR(100)
AS
BEGIN
SET NOCOUNT ON;
select * from order @mywhere
END
Gail missed a great chance to toot her own horn. Take a look at the following article. The method Gail uses not only allows for the dynamic SQL that you're looking for but is also great for "catch all queries" (very similar in nature to your query) and it's all done without any chance of SQL Injection.
Giving Jeff the assist (the link to the article):
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/[/url]
Ah, thanks for the cover, Matt. I was posting in a hurry and flat left out the links. I appreciate it.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 9, 2014 at 9:09 am
Sean Pearce (9/9/2014)
Without trying to sound anal, it is a Where Clause and not a Sentence.
Makes no difference in terms of SQL injection.
😎
September 10, 2014 at 4:37 am
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply