Click here to Skip to main content
15,897,187 members
Home / Discussions / Database
   

Database

 
GeneralDatagrid update and current row under edit. Pin
Itanium1-Jun-05 2:09
Itanium1-Jun-05 2:09 
GeneralSQL Oraclce code to SQL2000 convertion Pin
Mohammad Daba'an31-May-05 22:26
Mohammad Daba'an31-May-05 22:26 
GeneralPerformance around SQL and C# Pin
ouvrard31-May-05 21:46
ouvrard31-May-05 21:46 
GeneralRe: Performance around SQL and C# Pin
Colin Angus Mackay31-May-05 21:52
Colin Angus Mackay31-May-05 21:52 
GeneralRe: Performance around SQL and C# Pin
ouvrard31-May-05 21:55
ouvrard31-May-05 21:55 
GeneralSql access with user control Pin
ShugMagoo31-May-05 12:00
ShugMagoo31-May-05 12:00 
GeneralDatabinding in Master/Detail WinForm Pin
kb4mindia31-May-05 2:20
kb4mindia31-May-05 2:20 
GeneralQ: MsSQL dynamic Search with lot of conditions Pin
Stan Angeloff31-May-05 1:52
Stan Angeloff31-May-05 1:52 

Hi there!

Over the past few years I've worked on a number of websites. I've implemented a Search with varying conditions many times, but now it's different. So far the Search used stored procedures and dynamic SQL:

DECLARE @select_fields NVARCHAR(1024)
DECLARE @where_clause NVARCHAR(4000)
DECLARE @join_clause NVARCHAR(2048)
DECLARE @query NVARCHAR(4000)

SET @select_fields = '...'
SET @join_clause = '' 
SET @where_clause = ' WHERE 1 = 1'

...

IF @in_field1 IS NOT NULL
SET @where_clause = @where_clause + ' AND [table1].[field1] = @in_field1'

IF @in_field2 IS NOT NULL
SET @where_clause = @where_clause + ' AND [table2].[field2] = @in_field2'

...

SET @query = 'SELECT' + @select_fields + ' FROM [table1] AS [t1]' + @join_clause + @where_clause

DECLARE @params_def NVARCHAR(1024)

SET @params_def = '@in_field1 TYPE, @in_field2 TYPE, ...'

EXEC sp_executesql @query, @params_def,
@in_field1 TYPE,
@in_field2,
...

But now I'm facing an application that is requiring an advanced search with about 35-40 conditions, some of them arrays. I can't use the code above, because the @query variable is only 4000 characters long. As you can imagine, 35-40 conditions won't fit in it Frown | :( .

What is the best way to implement this Search using stored procedures? I don't want to build the SQL code in the program code and pass it to the stored procedure.

Thank you.
Stanimir.


GeneralRe: Q: MsSQL dynamic Search with lot of conditions Pin
Christian Graus31-May-05 12:06
protectorChristian Graus31-May-05 12:06 
GeneralRe: Q: MsSQL dynamic Search with lot of conditions Pin
Stan Angeloff1-Jun-05 7:14
Stan Angeloff1-Jun-05 7:14 
GeneralRe: Q: MsSQL dynamic Search with lot of conditions Pin
Christian Graus1-Jun-05 11:34
protectorChristian Graus1-Jun-05 11:34 
GeneralThank you! Pin
Stan Angeloff2-Jun-05 8:28
Stan Angeloff2-Jun-05 8:28 
GeneralRe: Thank you! Pin
Christian Graus2-Jun-05 10:17
protectorChristian Graus2-Jun-05 10:17 
GeneralRe: Thank you! Pin
Vertyg05-Jun-05 1:53
Vertyg05-Jun-05 1:53 
GeneralRe: Thank you! Pin
Christian Graus5-Jun-05 11:18
protectorChristian Graus5-Jun-05 11:18 
GeneralFunction returning Table (SQL) Pin
LIUCKAS31-May-05 0:28
LIUCKAS31-May-05 0:28 
GeneralExecuting a query Pin
Pothirajan C30-May-05 19:15
Pothirajan C30-May-05 19:15 
GeneralRe: Executing a query Pin
MasudM30-May-05 21:17
MasudM30-May-05 21:17 
GeneralRe: Executing a query Pin
Colin Angus Mackay30-May-05 22:18
Colin Angus Mackay30-May-05 22:18 
GeneralUpdate query Pin
jetset3230-May-05 1:19
jetset3230-May-05 1:19 
GeneralRe: Update query Pin
Christian Graus30-May-05 12:16
protectorChristian Graus30-May-05 12:16 
GeneralRe: Update query Pin
Anonymous2-Jun-05 3:37
Anonymous2-Jun-05 3:37 
GeneralRe: Update query Pin
jetset324-Jun-05 10:49
jetset324-Jun-05 10:49 
GeneralRe: Update query Pin
Christian Graus5-Jun-05 11:17
protectorChristian Graus5-Jun-05 11:17 
GeneralRe: Update query Pin
jetset3217-Jun-05 22:03
jetset3217-Jun-05 22:03 

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.