473,769 Members | 6,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Passing Multi Value Parameter in SQL Query

I have a query :
Exec 'Select * From Receiving Where Code In (' + @pCode + ')'

@pCode will contain more than one string parameter, eg : A1, A2, A3

How can i write that parameters, I try use :
set @pCode='A1','A2 ','A3'
but get an error : Incorrect syntax near ','
Please help me

Thanks

Jul 23 '05
10 125461
[posted and mailed, please reply in news]

Akash Kava (ac****@hotmail .com) writes:
Even I was looking for same and I found a great method to overcome your
problem. Trick is not to use IN clause and use the strings functions.

So the easiest way to think is wherever you write

( Column IN (@Params) )

you just replace above peice of code with

( CHARINDEX( QUOTENAME( Column , '''' ), @Params)<> -1 )
Background:

if you want to find out wheather "b" exists in a,b,c or not use this.

@Params = "a,b,c"

CHARINDEX( Column , @Params ) <> -1

this will turn on true if column has a , b or c in it.


Warning! This method have serious performance problems, even with
short lists. First of all any index on Column will not be used.
But even if the column is not indexed - in which case this does not
matter - this operation is very expensive. When I ran performance
tests a couple of years ago on various methods, a list that was
around 255 character long cause a search to take 40 seconds!

That test, as well as several other - and better! - methods to tackle
this problem is described in an article on my web site. See
http://www.sommarskog.se/arrays-in-sql.html.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Aug 2 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3863
by: Michael DeLawter | last post by:
Using Access 2002. I have a chart in a report that is currently based on a query in which the user enters the start and end date for the chart to display. Both the start and end dates have been identified as parameters so that the date range can be found without causing an error. So far so good, report works as it should. Here's the problem. There are several reports that need to be printed at the end of month that use the same...
5
4301
by: MX1 | last post by:
Simpler way to ask question from my previous post. I wrote a query and it has a paramter field in it. I want to enter a date with the current year. If it I put in 6/30/2003, it works great. If I put in some kind of a variable based input for the parameter like '6/30/' & year(now()), it doesn't work. Is there any way to concatenate text and a variable at the input of a parameter query. THIS IS DRIVING ME NUTS. PLEASE HELP. :)
3
7550
by: MX1 | last post by:
I'm ready to pull the hair out of my head. I have a query with a couple of parameters that I want to get from combo boxes on a form. One parameter is a date with a dynamically calculated year and the other is criteria for a Yes or No field. I'll focus on the Yes/No field for simplicity. If I run the query with the criteria hard coded as either "YES" or "NO", it works. In the values of the combo box in my form, I have it set as...
1
2439
by: Yodel99 | last post by:
Greetings, I have a form (Form1) based on a parameter query (Query1). I want the value that the user enters in the parameter window to populate a field in the form. I've been able to use the following to capture the value if the qry is satisfied, and put it in a column in the qry. PARAMETERS value Text (255); SELECT DISTINCTROW ., AS Expr1 FROM Table1 WHERE (((Table1.lastname)=));
1
2579
by: carrionk | last post by:
Hi, I have created a Subform which SourceObject is a parameter query. This is the Query: Qry Name:80IsscomProduct SELECT * FROM Isscomp28 WHERE Like ;
2
3998
by: dath | last post by:
Hi, Searched the forum and found a lot on passing form input to aquery but not the other way around. Here is the situation: I have a timesheet form based on a subform query that asks the user for the Month and their last name. The fields in the table being updated include: FY, Month, Employee ID, Task Number, hours. The query then displays the results in data sheet view on the form. I have been asked by users to display total they...
12
2594
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned by value temporaries are created?(I'm not touching yet the cases where standard allows optimizations from the side of implementations to avoid copying) If so, please quote part of the standard that says that. Assuming it is true, I can imagine two...
5
5307
by: Trevisc | last post by:
Happy Thursday Everyone, I am trying to create a parameter that is one long varchar but that will be used in a SQL statement IN function: //string queryString = GetCurrentTitles(); //Below is for Test string queryString = "45322,32222,33344,55555"; dataset catalogDS = new dataset();
3
10840
by: timleonard | last post by:
I use a query to select several fields from the table including a multi-value field. I then use the "DoCmd.TransferSpreadsheet acExport acSpreadsheetTypeExcel12" to send the info to an excel.xlsm file. It appears that this method does not like the multi-value fields. Is there a way to extract or convert the data in the multi-value field to single value during the query?
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.