473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

function is not working 'in operator' method in stored procedure

2
I am trying to execute below sp but i am unable to get the result.

reasion is i am using function which is return string values like ('ab','df','dfff').when i use this function in operator it is not returning any value ..anybody help me why it is not returning ?.

Expand|Select|Wrap|Line Numbers
  1. function name ([dbo].fnParseSplitString(@stQueueName)))
  2.  
  3.  
  4. ALTER PROCEDURE [Strategies_uspGetNoCreditBureauReview]
  5.     -- Add the parameters for the stored procedure here
  6.     @StrategiesId int
  7.  
  8. AS
  9. BEGIN
  10.     -- SET NOCOUNT ON added to prevent extra result sets from
  11.     -- interfering with SELECT statements.
  12.     SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  13.  
  14.     DECLARE @stQueueName varchar(50) 
  15.  
  16.     SET NOCOUNT ON;
  17.     if @StrategiesId is not null 
  18.     begin
  19.     -- select statements for procedure here
  20.     select @stQueueName = (SELECT StrategiesQueueandWamName from [dbo].[Strategies] where StrategiesId = @StrategiesId)
  21.  
  22.         select qc.QueueId,qc.QueueName,wc.WamName,lc.LocationName
  23.         from Channelsmapping cm
  24.         join [dbo].[QueueChannels]  qc on 
  25.         cm.QueueId = qc.QueueId
  26.         join LocationChannels lc on
  27.         lc.LocationId = cm.LocationId
  28.         join [dbo].[WamChannels] wc on
  29.         wc.WamId = cm.WamId
  30.         where qc.Queueid in (select queueid from [dbo].[QueueChannels] where queuename in ([dbo].fnParseSplitString(@stQueueName)))
  31.         group by qc.QueueId,qc.QueueName,wc.wamname,lc.locationname
  32.         order by qc.QueueId,qc.QueueName,wc.wamname,lc.locationname asc
  33.     End
  34. END
Sep 19 '13 #1
3 2728
Rabbit
12,516 Expert Mod 8TB
There's not enough information to answer this question. We need to know what value @stQueueName holds. And we need to know the code for the function fnParseSplitString because that is not a native function in SQL Server. Someone on your side created that.
Sep 19 '13 #2
asok
2
I will pass the value to function like 'abc,defd,ghjk' and function will return the value like 'abc','defd','ghjk' so that i can use 'IN' Operate to get the values from database.

Here is the function which return the values

Expand|Select|Wrap|Line Numbers
  1. ALTER FUNCTION [dbo].[fnParseSplitString] 
  2. @InputString varchar(255) 
  3. RETURNS varchar(255) 
  4. AS 
  5. BEGIN 
  6.     DECLARE @ParsedInputString varchar(255) 
  7.     DECLARE @ExcludedCourse varchar(10) 
  8.     DECLARE @Pos int 
  9.  
  10.     WHILE LEN(@InputString) > 0 
  11.     BEGIN 
  12.         SET @Pos = CHARINDEX(',',@InputString) 
  13.  
  14.         IF @Pos = 0 
  15.             BEGIN 
  16.                 SET @ParsedInputString = ISNULL(@ParsedInputString,'') + '''' + LTRIM(@InputString) + '''' 
  17.             END 
  18.         ELSE 
  19.             BEGIN 
  20.                 SET @ExcludedCourse = '''' + SUBSTRING(@InputString, 1, @Pos - 1) + '''' 
  21.                 SET    @ParsedInputString = @ExcludedCourse + ',' + ISNULL(@ParsedInputString,'') 
  22.             END 
  23.  
  24.         IF @Pos = 0 
  25.             BEGIN 
  26.                 SET @InputString = '' 
  27.             END 
  28.         ELSE 
  29.             BEGIN 
  30.                 SET @InputString = LTRIM(SUBSTRING(@InputString, @Pos + 1, LEN(@InputString) - @Pos)) 
  31.             END 
  32.     END 
  33.  
  34. RETURN @ParsedInputString 
it is working when I manually enter the values like

select queueid from queue where queuename in ('abc','defd','ghjk')

it is not working when i use function in 'IN' operator like

select queueid from queue where queuename in ([dbo].fnParseSplitString(@stQueueName)))

function return Varaiable @stQueueName will have the data like ('abc','defd','ghjk').

Please help me why it is not returning the values while using function in 'IN' Operator.
Sep 20 '13 #3
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

The IN operator expects one or more values separated by commas. What you gave it is one string. The string just happened to contain commas. It does not see it as separate values.

In essence what you have done is pass this into the WHERE clause:
Expand|Select|Wrap|Line Numbers
  1. fieldName IN ('''a'',''b''')
But what it's really expecting is this:
Expand|Select|Wrap|Line Numbers
  1. fieldName IN ('a','b')
The difference between the first and second is that the first is only one string, the second is two strings. You have only passed one string because that's what your function returns. You need to modify your function to return multiple strings in the form of a table.
Sep 20 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: M Wells | last post by:
Hi All, I have a table that holds pregenerated member IDs. This table is used to assign an available member id to web site visitors who choose to register with the site So, conceptually the...
4
by: Rodusa | last post by:
I am having problem to apply updates into this function below. I tried using cursor for updates, etc. but no success. Sql server keeps telling me that I cannot execute insert or update from inside...
4
by: Chris Auer | last post by:
What I am looking to do is use a complicated stored procedure to get data for me while in another stored procedure. Its like a view, but a view you can't pass parameters to. In essence I would...
3
by: shsandeep | last post by:
Hi gurus, i have written a stored procedure in a file sampleproc.sql DB2 V8.2 AIX V5.3 Is this first step correct? If yes, what are the next steps? Sorry for such a silly question but am a...
4
by: hicks | last post by:
I'm trying to invoke a DB2 stored procedure. The stored proc is coded in C and compiled to a shared library, which has been placed in the <DB2 dir>/functions directory. The platform is Solaris....
7
by: ashtek | last post by:
Hi, I have a generic function that executes a stored procedure & returns a data table. Code: === public static DataTable ExecuteStoredProcedure(string strProc,SqlParameter paramArray) {...
6
by: rocksoft | last post by:
Hi, i'm using mysql database, i don't know syntax how to pass the parameter in like operator inside the stored procedure, i want to select the store number related to textbox input number...
1
by: uvasag | last post by:
I'm converting SQL Server code into Oracle and would like to know if I can create and drop a function from inside an Oracle stored procedure. The SQL Server code seems to do it but when I try the...
1
by: apothecary | last post by:
Hello Newbie here. Is there a way of creating a VIEW...using a stored procedure. I am basically trying to create a view to return some data that I am getting using a stored procedure. I...
1
by: anoopmadavoor | last post by:
Hello, Is it possible to call a python function from a postgresql stored procedure,pls give me an example
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...

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.