Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Accessing SQL variables within"WITH" statement

Posted on 2014-04-23
7
214 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 33

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 33

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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