Solved

Accessing SQL variables within"WITH" statement

Posted on 2014-04-23
7
207 Views
Last Modified: 2014-04-29
Hi
I'm trying to add an input variable (part_number) to my SQL Stored Proc but it seems to ignore the value I pass into the Stored Proc.

The only odd thing with the Stored Proc is that it uses the "WITH" convention to optimise it, and I'm wondering if you have to access a variable differently when used within the "WITH" convention? thanks
Fergal
0
Comment
Question by:fjkilken
  • 3
  • 2
  • 2
7 Comments
 
LVL 32

Expert Comment

by:ste5an
ID: 40017542
No,  but are you using this parameter in your sproc?
0
 

Author Comment

by:fjkilken
ID: 40017574
Yes, it's being refernced in the proc, I'm trying to pass a "part_number" value into the proc
0
 
LVL 32

Expert Comment

by:ste5an
ID: 40017714
Well, then you should post your procedure and it's invokation. Cause my Crystal Ball (tm) is not working right now..Crystal Ball (tm)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:fjkilken
ID: 40017762
ha ha - good point, I'm just trying to trim-down the query now to the pertinent code, but the issue is that now the parameter IS being recognised, so I'm trying to determine from the removed code as to what could be causing the parameter to be blocked.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 40026354
You do realize we have no idea what you are talking about, right?  

If you want help, try posting your query and explain what you are trying to achieve.
0
 

Author Comment

by:fjkilken
ID: 40027742
Thanks for the comments - after cleaning-up my query in prep. for posting it here, my variable is now functioning as expected, I'm not sure exactly what fixed it but it's now working.
In relation to this however, I need to be able to pass-in multiple values as in a SQL "IN" query, for example;
instead of simply using a single value-

WHERE @StockNumber = 'ABC'

I'd like to be able to do:

WHERE @StockNumber IN ('ABC','123','XYZ')

- is this possible?
Thanks!
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 40027992
Yes.  There are a number of ways (from good to bad):
1. Table-Valued parameters.
2. Xml
3. Delimted string.
4. Dynamic SQL.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now