473,322 Members | 1,403 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,322 software developers and data experts.

SQL Server - Building dynamic query

I want to be able to build a query with a variable amount of where statements. A user will be adding various conditions. Is there a way to make a query flexible? In Microsoft access I would write visual basic code and have it loop thru and add the various where statements. I am new to SQL server so excuse me if I don't have the terminology correct. Thanks for the help.
Sep 27 '07 #1
1 2738
ck9663
2,878 Expert 2GB
I want to be able to build a query with a variable amount of where statements. A user will be adding various conditions. Is there a way to make a query flexible? In Microsoft access I would write visual basic code and have it loop thru and add the various where statements. I am new to SQL server so excuse me if I don't have the terminology correct. Thanks for the help.
if you have a GUI, you can build the string in your GUI then execute the through Execute Method of your front-end tool the same way you to in MS Access. if you're planning to use stored procedure you can build your query by something like:

set @sqlstringvariable = 'select field from table'
set @sqlstringvariable = @sqlstringvariable + ' where ' + @condition1
set @sqlstringvariable = @sqlstringvariable + ' and ' + @condition2

then do a

exec ( @sqlstringvariable)
Sep 28 '07 #2

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

Similar topics

22
by: Fawke101 | last post by:
Hi there, I am having trouble with some data that is ripped from a SQL database and displayed as a hyperlink. The hyperlink inserts the data into a querystring so the next page can read it. ...
6
by: Jegger | last post by:
Hello! We have following situation; network with 100 users, aplication developed in Access, user DB deployed on SQL Server. Is it better to create query inside aplication (with code) and then...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
4
by: Brian Shannon | last post by:
I have 3 combo boxes and two date text boxes on a .aspx page. The user can fill in any of the 5 controls or none to filter a datagrid. I was hoping someone could explain how to efficiently build...
1
by: mrcraze | last post by:
Hi Everyone! We are using a cursor for paging results in SQL server, mainly due to the performance gains achieved when working with large results sets. We have found this to be of great benefit...
3
by: s_wadhwa | last post by:
Hi, I'm trying to convert MS Access 97 .mdb application to Access 2003 .adp application with SQL Server as Backend. I'm having trouble converting Access Query into SQL Query. The Query is...
8
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table,...
3
by: wsox66 | last post by:
I am new to Access and need some help building a report. I have looked through previous posts on reports but none of them seem to answer my question completely. I am using Access 2003 and I have...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.