1 Replies - 812 Views - Last Post: 17 March 2010 - 03:47 PM Rate Topic: -----

#1 jjsaw5   User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 3,063
  • Joined: 04-January 08

Passing a Null Value into a Sql statement

Posted 16 March 2010 - 12:13 PM

I have a reports page that I am passing parameters from and they are going into a sql statement. Not all of the required fields on the reports page need to be filled in.

For example I currently have the report being generated based off of a FROM DATE and a TO DATE. This works just fine. My issue lies in the fact that the user would like the ability to run this report based off of other fields….

Requestor
Analyst
Fund Type

So I need my SQL statement to be able to handle if they only choose on criteria or all. How can I modify the below SQL statement to all handle this?

sql = "      SELECT   REQUEST_ID, DATE, PROF_ANAYLST_ID, REQUESTOR_DEPT, CHANNEL, ANALYSIS_TYPE, COMP_TICKER, COMP_FUND_TYPE, "
  sql = sql & "         FED_TICKER, FED_FUND_TYPE "
  sql = sql & "FROM     [Ticker_App] "
  sql = sql & "WHERE DATE between '" & FROMDATE & "' and '" & TODATE & "'"


Is This A Good Question/Topic? 0
  • +

Replies To: Passing a Null Value into a Sql statement

#2 thava   User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,607
  • Joined: 17-April 07

Re: Passing a Null Value into a Sql statement

Posted 17 March 2010 - 03:47 PM

just like this

sql = "      SELECT   REQUEST_ID, DATE, PROF_ANAYLST_ID, REQUESTOR_DEPT, CHANNEL, ANALYSIS_TYPE, COMP_TICKER, COMP_FUND_TYPE, "
  sql = sql & "         FED_TICKER, FED_FUND_TYPE "
  sql = sql & "FROM     [Ticker_App] "
  sql = sql & "WHERE DATE between '" & FROMDATE & "' and '" & TODATE & "'"
If ANALYST_ID >0 Then
sql = sql & "and PROF_ANAYLST_ID =" & ANALYST_ID & " "
END IF


hope you got it
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1