Date Range or Columns values entered in Prompt need to be used as variables in Spotfire IL modified SQL

。_饼干妹妹 提交于 2019-12-24 08:15:30

问题


I need to use the prompted input of a date range/any column to be used as a variable in the modified SQl feature of the Information Link. I have some complex queries which uses multiple conditions and i wont be able to keep them in the view and want to add those conditions in modified SQL using this variable.

This is a sample SQL where i need to use the variable/parameter instead of the dates given

SELECT xxxxx.yyyy

  FROM xxxxx, xxxxx, xxxxx, xxxxx

WHERE xxxxx.yyyyy = xxxxx.yyyyy


   AND ( ((    xxxxx.yyyy >= (TO_DATE ('11/01/2015', 'MM/DD/YYYY'))
             AND xxxxx.yyyy <  (TO_DATE ('12/1/2015', 'MM/DD/YYYY'))
             AND xxxxx.zzzzz >=    (TO_DATE ('11/01/2015', 'MM/DD/YYYY'))
             AND xxxxx.zzzzz < (TO_DATE ('12/1/2015', 'MM/DD/YYYY')) ))

        OR ((    xxxxx.zzzzz >= (TO_DATE ('11/01/2015', 'MM/DD/YYYY'))
             AND xxxxx.zzzzz < (TO_DATE ('12/1/2015', 'MM/DD/YYYY'))
             AND xxxxx.yyyy =  (TO_DATE ('01/01/1753', 'MM/DD/YYYY')) ))

        OR ((    xxxxx.zzzzz >=  (TO_DATE ('11/01/2015', 'MM/DD/YYYY'))
             AND xxxxx.zzzzz < (TO_DATE ('12/1/2015', 'MM/DD/YYYY'))
             AND xxxxx.yyyy > (TO_DATE ('10/15/2015', 'MM/DD/YYYY'))
             AND xxxxx.yyyy <  (TO_DATE ('12/1/2015', 'MM/DD/YYYY')) )) )

I need the above where conditions to be added into the Information link modified SQL with the parameter to be like this

WHERE xxxxx.yyyyy = xxxxx.yyyyy


       AND ( ((    xxxxx.yyyy >= @parameter1
                 AND xxxxx.yyyy <  @parameter2
                 AND xxxxx.zzzzz >=    @parameter1
                 AND xxxxx.zzzzz < @parameter2

Let me know if further clarification is required.


回答1:


This will only work for one condition. That is >= or <= to all of the dates in xxxxx.yyyy column. So, if you MUST use a view then you need to use prompts in the information designer. Here is how:

  1. Open your Information Link in Information Designer
  2. Leave your SQL alone. Set the date range to the largest range you'll need
  3. Under the Prompts section, Add a prompt for your xxxxx.yyyy column
  4. Set the Prompt Type to Range and check the Mandatory box

Now, add the Information Link to your analysis...

  1. When the prompt window opens, select the Use On-demand button at the bottom. Select OK/ Finish
  2. On the Tool Bar go to Edit > Data Table Properties and select your data table
  3. Select the Settings button under Type of data: within the General tab
  4. Highlight your xxxxx.yyyy column and click the Define Input button
  5. Select Values (fixed/properties/expression) from the drop down for Input for the selected parameter
  6. Select the Property radio button and click the Select button
  7. Click New and create a property control of type DATE which you will use in a text area

Again, this is not the ideal way. If you TRULY want to use multiple parameters in multiple conditions, we need to convert your view to a procedure or table-valued function. it's not hard.


EDIT

CREATE PROCEDURE dbo.myProcedure(@parameter1 datetime, @parameter2 datetime)
AS

SELECT xxxxx.yyyy

FROM xxxxx, xxxxx, xxxxx, xxxxx

WHERE xxxxx.yyyyy = xxxxx.yyyyy

     AND xxxxx.yyyy >= @parameter1
     AND xxxxx.yyyy < @parameter2
     AND xxxxx.zzzzz >= @parameter1
     AND xxxxx.zzzzz < @parameter2

Then, you can test the execution by entering this in a new SSMS window.

EXEC dbo.myProcedure '4/1/2016','7/1/2016' --or what ever dates you want to pass in.


来源:https://stackoverflow.com/questions/38225091/date-range-or-columns-values-entered-in-prompt-need-to-be-used-as-variables-in-s

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!