473,662 Members | 2,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parameter in select statement

2 New Member
Hi,

I need to pass a parameter into a stored procedure which values are dynamic always. Executing a variable which having the Select statement.


Following query working fine.

Expand|Select|Wrap|Line Numbers
  1. BEGIN
  2. DECLARE @strQuery NVARCHAR(MAX)
  3. DECLARE @CountryId INT
  4. DECLARE @CityId INT
  5.  
  6. SET @CountryId = 2
  7. SET @CityId = ' AND CityId IN (23,45,85,86)'
  8.  
  9. SELECT @strQuery= 'SELECT VendorId From Vendors
  10. WHERE CountryId = '+@CountryId+' '+@CityId+'
  11. ORDERBY CreatedDate'
  12.  
  13. EXEC(@strQuery)
  14. END
I need to execute above in an open select statement instead of executing @strQuery.

Getting error as When trying through following script as "Conversion failed when converting the varchar value ' AND CityId (23,45,85,86)' to data type int"

Expand|Select|Wrap|Line Numbers
  1. SELECT VendorId From Vendors
  2. WHERE CountryId = @CountryId + ' ' +@CityId 
  3. ORDERBY CreatedDate
Please help me to get it working through above select statement.

Thanks

Sharma
Oct 4 '10 #1
1 1691
gpl
152 New Member
See my answer in this question
http://bytes.com/topic/sql-server/an...ing-into-query
Oct 5 '10 #2

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

Similar topics

1
11108
by: avinash | last post by:
hi myself avi i am developing one appliacaion in which i am using vb 6 as front end, adodb as database library and sql sever 7 as backend. i want to update one table for which i required data from other table. and iretrive data from second table by giving some condition. when i get data, then to update first table i need to use do while loop. instead of that i want to use select statement directly in update query. plz give me some help....
2
1578
by: GIS Analyst | last post by:
Hi to all I wish to be able to have a standard select statement which has additional fields added to it at run-time based on supplied parameter(s). ie declare @theTest1 nvarchar(10) set @theTest1='TRUE'
6
26533
by: Terentius Neo | last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a select statement? I mean something like this: Select c.number, call procedure( c.number ) as list from table c With best regards
3
3104
by: kscdavefl | last post by:
I am using the following select statement in a web app where I take the cvalue in a text box and conduct a search of the database. "Select wo18 from workorder where wo9 = " + "'" + programText.Text + "'"; I want to search the text box to see if it contains % and if it does I want to use like in the select statement above instead of =. It should look something like this: if (programText.Text contains '%') {
3
2683
by: Brian Conway | last post by:
I am trying to get a parameter passed from one page to another in a QueryString to get inserted into the select statement on the page that is getting called. If I hard code in a value everything works, but I can't figure out how to get it to pass in as a parameter. Here is what I have. The parameter section doesn't work though. OleDbConnection conn = new OleDbConnection(ConfigurationSettings.AppSettings); OleDbDataAdapter da = new...
3
968
by: Manuel Canas | last post by:
Hi there, This is the code that I'm trying to build to retrieve data from the database. strSQL = "SELECT RTRIM(LastName) + ', ' + FirstName AS FullName, PatientID FROM tb_Patient " & _ "WHERE LastName LIKE @PatientSearch"
1
4587
by: Khodr | last post by:
Hi everyone, I am calling an Oracle StoredProc that returns a CLOB data type value as an output parameter. What parameter data type should I use? >> I tried adLongVarChar and adVarChar with the sizes 1000, 32000, 1000000 and they all fail. Size of returned value will exceed 50k. >> I know that there is a GetChunk, but I noticed that it applies only to SELECT statement. In my case, I have a StoredProc. >> I am using ADODB version 2.7 >>...
1
1488
by: luvic.vangool | last post by:
Hi, I'm fairly new to MySql and come from a MS SQL background. I have an application that I am converting from MS SQL to MySql. I need to return a value from MySql using a parameter. In MS SQL my select statement is: "select @id = id from database"
1
5402
by: VB Programmer | last post by:
I have a SqlDataSource I setup on an ASP.NET 2.0 webform. I setup the SELECT statement and it has 1 parameter, @ProductId. How do I, using VB.NET, store the results of that SELECT statement into a datatable or dataview, for example? Here's partial code... Dim ds As New DataSet Dim dv As New DataView
2
4825
by: ankitmathur | last post by:
Hi All, I'm facing a problem I'm unable to find a solution for. I hope fellow members would be able to help me out. System Info: PHP v5 MSSQL 2008 Linux box
0
8345
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
8857
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
8547
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
7368
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
6186
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
5655
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();...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2763
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
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.