Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,047 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,566 people online right now. Registration is fast and FREE... Join Now!




Query Problem (all values)

 
Reply to this topicStart new topic

Query Problem (all values)

vb6_god
4 Aug, 2008 - 06:33 PM
Post #1

New D.I.C Head
*

Joined: 3 Dec, 2007
Posts: 26


My Contributions
Hey there ill keep it sweet and simple...Im making a search query in a web page.. but i if no input is selected i simply want it to ignore that part of the query.....

for example ...I know that

CODE


SELECT * FROM TABLE
WHERE
Columnname = Columnname


this will ignore the where as it will select all of the column values.

But i want to know how i can do this when im passing a variable in Vbscript.....

Im using the parameter append command to link the two

CODE


.Parameters.Append .CreateParameter("@Columnname", adInteger, adParamInput, 4, Int(Columnname))


What value can i store in the Columnname that will do the Columnname = Columnname function ??????





Also if it makes it easier, Does MSSQL support IF ...ELSE Sequences and if it does again what would i set a integer parameter to, so that i could get the columnname = column name function.....

Do i use; '%%' because i tried this and it didnt work sad.gif


Anyways simple but SOOOO ANOYING ! lol

Thanks

User is offlineProfile CardPM
+Quote Post

AdaHacker
RE: Query Problem (all Values)
5 Aug, 2008 - 05:35 AM
Post #2

D.I.C Head
**

Joined: 17 Jun, 2008
Posts: 173



Thanked: 27 times
My Contributions
What's wrong with just leaving the WHERE clause off the query? If you're doing this from VBScript, then just detect when no input is submitted and, in that case, just run a plain-old "SELECT * FROM TABLE". If input is submitted, then do what you're doing now. You get the same effect, and in my opinion, it's clearer than trying to create a parameterized WHERE clause that always evaluates to true.
User is offlineProfile CardPM
+Quote Post

vb6_god
RE: Query Problem (all Values)
5 Aug, 2008 - 07:53 PM
Post #3

New D.I.C Head
*

Joined: 3 Dec, 2007
Posts: 26


My Contributions
QUOTE(AdaHacker @ 5 Aug, 2008 - 06:35 AM) *

What's wrong with just leaving the WHERE clause off the query? If you're doing this from VBScript, then just detect when no input is submitted and, in that case, just run a plain-old "SELECT * FROM TABLE". If input is submitted, then do what you're doing now. You get the same effect, and in my opinion, it's clearer than trying to create a parameterized WHERE clause that always evaluates to true.



Ok so i didnt mention before that the query im using does alot more than just pull this one field...this field is just required in the other coding and the sql code is stored in a procedure in MS SQL clearly becuase its quicker than loading new code each time.

So again im stuck with the same problem. If i was in a position to just ignore the WHERE statment i would have done already. But thanx for the input nobody else seems to be interested


User is offlineProfile CardPM
+Quote Post

AdaHacker
RE: Query Problem (all Values)
6 Aug, 2008 - 07:55 AM
Post #4

D.I.C Head
**

Joined: 17 Jun, 2008
Posts: 173



Thanked: 27 times
My Contributions
QUOTE(vb6_god @ 5 Aug, 2008 - 10:53 PM) *

Ok so i didnt mention before that the query im using does alot more than just pull this one field...

Ah, I see. Well, that would definitely make the question a bit more interesting.

QUOTE(vb6_god @ 4 Aug, 2008 - 09:33 PM) *

Also if it makes it easier, Does MSSQL support IF ...ELSE Sequences and if it does again what would i set a integer parameter to, so that i could get the columnname = column name function.....

I don't know a great deal about SQL Server inparticular, but in ANSI SQL you can do something like this with a CASE expression:
SQL
SELECT * FROM ... WHERE ColumnName = CASE
WHEN :param = 0 THEN ColumnName
ELSE :param END;

When you pass in :param as 0, the CASE expression evaluates to ColumnName and effectively eliminates that condition. Otherwise, it evaluates to the value of :param. Of course, you would need to pick a suitable "dummy" value based on what kind of data you have, but this should give you the general idea.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 05:19PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month