Results 1 to 2 of 2

Thread: SQL server case statement??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    137

    SQL server case statement??

    I'm trying to pass an operator(>,<,=) and numeric text box value to a SQL stored procedure. I would like to know the proper syntax for the following SQL case statment. I want to use each operator as a case. for example, if the operator is >, then select values from a column where the values are greater tha the textbox variable. if the operator is <, then select values from a column that are less than the textbox value.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: SQL server case statement??

    Give this a try:

    Code:
    SELECT .....
    WHERE
        CASE 
             WHEN @operator = '>' AND Field > @TxtBoxVal THEN 1
             WHEN @operator = '<' AND Field < @TxtBoxVal THEN 1
             WHEN @operator = '=' AND Field = @TxtBoxVal THEN 1
             ELSE 0
        END = 1
    It's a bit on the creative side,.... but I've done that kind of stuff before and it works... hopefully it's what you need.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width