Click here to Skip to main content
15,917,622 members
Home / Discussions / Database
   

Database

 
GeneralRe: slow updating [modified] Pin
Xmen Real 3-Apr-08 22:27
professional Xmen Real 3-Apr-08 22:27 
GeneralRe: slow updating Pin
Blue_Boy4-Apr-08 7:22
Blue_Boy4-Apr-08 7:22 
GeneralRe: slow updating Pin
Xmen Real 4-Apr-08 7:25
professional Xmen Real 4-Apr-08 7:25 
GeneralRe: slow updating Pin
Blue_Boy4-Apr-08 8:01
Blue_Boy4-Apr-08 8:01 
GeneralRe: slow updating Pin
Xmen Real 4-Apr-08 14:51
professional Xmen Real 4-Apr-08 14:51 
QuestionCalling Web Service From SQL Stored Procedures Pin
Adewale3-Apr-08 5:25
Adewale3-Apr-08 5:25 
GeneralRe: Calling Web Service From SQL Stored Procedures Pin
pmarfleet3-Apr-08 9:38
pmarfleet3-Apr-08 9:38 
QuestionPassing IN clause to SP via Parameter Pin
stuebbie3-Apr-08 3:53
stuebbie3-Apr-08 3:53 
Hi,

I'm trying to send a parameter to a Stored Proc from ASP.NET in the form of a list of values to be used in an IN clause. However, the IN clause is looking up a column of type int, and I am getting a syntax error when I try to execute the SP:

C# code calling SP

<br />
<br />
SqlConnection conn      = new SqlConnection(sqlT.getServerConnString("ConnString"));            <br />
        SqlCommand cmd          = new SqlCommand();<br />
        cmd.Connection          = conn;<br />
        cmd.CommandType         = CommandType.StoredProcedure;<br />
        cmd.CommandText         = "SlideShowAppGenProp";<br />
        SqlParameter param1     = new SqlParameter();<br />
        param1.SqlDbType        = SqlDbType.VarChar;<br />
        param1.Size             = 1500;<br />
        param1.Value            = strPropRefList;<br />
        param1.ParameterName    = "@refNumber";<br />
        cmd.Parameters.Add(param1);<br />
<br />


In the above code, strPropRefList is a string value in the following format:

"129759, 130009, 130427, 130635, 130646, 131258"

SP code:

<br />
<br />
PROCEDURE SlideShowAppGenProp<br />
	<br />
	(<br />
	@refNumber varchar(1500)	<br />
	)<br />
	<br />
AS<br />
	SELECT<br />
	<br />
	a.ID AS 'refNumber',<br />
	c.Description AS 'Area',<br />
	d.Description AS 'Region'<br />
<br />
from<br />
	tPty_Property a<br />
	INNER JOIN tLkp_PropertyGuideDistrict c<br />
	ON a.lkpPropertyGuideDistrictID = c.ID<br />
	INNER JOIN tLkp_PropertyGuideSection d<br />
	ON a.lkpPropertyGuideSectionID = d.ID<br />
	<br />
WHERE <br />
	a.ID IN (@refNumber)<br />
<br />
ORDER BY<br />
	a.ID<br />
<br />



Running the code as it is, I get the following error...

Server: Msg 245, Level 16, State 1, Procedure SlideShowAppGenXml, Line 8
Syntax error converting the varchar value '129759, 130009, 130427, 130635, 130646, 131258' to a column of data type int.


...which is understandable because SQL is treating the whole value as one string, and places single quotes at each end.

I don't want to have to rework my C#/SQL code to make multiple DB calls (the number of reference values in the parameter string can go as high as 50), so is there another way that I can pass this comma-separated list of values into a SQL Stored Proc IN clause?

Apologies if there is a really simple solution and I have missed it.

Thanks,

Stuart
GeneralRe: Passing IN clause to SP via Parameter Pin
Mark J. Miller3-Apr-08 4:13
Mark J. Miller3-Apr-08 4:13 
AnswerRe: Passing IN clause to SP via Parameter Pin
stuebbie3-Apr-08 21:57
stuebbie3-Apr-08 21:57 
GeneralRe: Passing IN clause to SP via Parameter Pin
SimulationofSai3-Apr-08 13:04
SimulationofSai3-Apr-08 13:04 
QuestionHow to register custom control Pin
lav naphade3-Apr-08 2:13
lav naphade3-Apr-08 2:13 
AnswerRe: How to register custom control Pin
pmarfleet3-Apr-08 9:34
pmarfleet3-Apr-08 9:34 
GeneralRegarding SQL Query Pin
sandhya143-Apr-08 1:28
sandhya143-Apr-08 1:28 
GeneralRe: Regarding SQL Query Pin
Rob Philpott3-Apr-08 2:37
Rob Philpott3-Apr-08 2:37 
QuestionWhat is the diffrence between CTE(Common Table Expression) and Derived table Pin
Krishnraj3-Apr-08 0:27
Krishnraj3-Apr-08 0:27 
GeneralRe: What is the diffrence between CTE(Common Table Expression) and Derived table Pin
Mark J. Miller3-Apr-08 4:50
Mark J. Miller3-Apr-08 4:50 
Generalselect distinct, but only on one column Pin
phimix2-Apr-08 21:50
phimix2-Apr-08 21:50 
GeneralRe: select distinct, but only on one column Pin
Rob Philpott2-Apr-08 22:27
Rob Philpott2-Apr-08 22:27 
GeneralRe: select distinct, but only on one column Pin
phimix2-Apr-08 23:12
phimix2-Apr-08 23:12 
QuestionHow grant ALTER on all tables to an user? Pin
blackjack21502-Apr-08 21:11
blackjack21502-Apr-08 21:11 
AnswerRe: How grant ALTER on all tables to an user? Pin
Mark J. Miller3-Apr-08 4:47
Mark J. Miller3-Apr-08 4:47 
GeneralRe: How grant ALTER on all tables to an user? Pin
blackjack21503-Apr-08 10:03
blackjack21503-Apr-08 10:03 
GeneralRetrieve the second biggest amount from a table Pin
Daniel_Logan2-Apr-08 21:03
Daniel_Logan2-Apr-08 21:03 
GeneralRe: Retrieve the second biggest amount from a table Pin
blackjack21502-Apr-08 21:16
blackjack21502-Apr-08 21:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.