473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Count diferent variables

1
Hello

I run one query to obtain a value until 30. I have to run the same query changing the condition from 30 to 60. Is posible to run in the same query this two results each one in one collum?

The query is:

select (CONVERT (VARCHAR,alarm_local_date,103)) AS DATA
, COUNT (full_clear_opactdisp_id) AS ALARMES

FROM ALARM_INCIDENT

WHERE (full_clear_opactdisp_id = 'ANL'
OR full_clear_opactdisp_id = 'CAN'
OR full_clear_opactdisp_id = 'CCA'
OR full_clear_opactdisp_id = 'CI'
OR full_clear_opactdisp_id = 'DDC'
OR full_clear_opactdisp_id = 'EA'
OR full_clear_opactdisp_id = 'EPL'
OR full_clear_opactdisp_id = 'FFS'
OR full_clear_opactdisp_id = 'FSA'
OR full_clear_opactdisp_id = 'FTL'
OR full_clear_opactdisp_id = 'MUE'
OR full_clear_opactdisp_id = 'PA'
OR full_clear_opactdisp_id = 'PAS'
OR full_clear_opactdisp_id = 'PJA'
OR full_clear_opactdisp_id = 'PSAE'
OR full_clear_opactdisp_id = 'PSE'
OR full_clear_opactdisp_id = 'SEM'
OR full_clear_opactdisp_id = 'RB'
OR full_clear_opactdisp_id = 'RC'
OR full_clear_opactdisp_id = 'REM'
OR full_clear_opactdisp_id = 'RI'
OR full_clear_opactdisp_id = 'RIC'
OR full_clear_opactdisp_id = 'RPP'
OR full_clear_opactdisp_id = 'RTL'
OR full_clear_opactdisp_id = 'VNR'
OR full_clear_opactdisp_id = 'VR')


AND (DATEDIFF(ss,alarm_local_date ,first_access_local_date ))<= '30'
AND alarm_local_date > '2007-07-11 00:00:00.000'
--AND alarm_local_date < '2006-05-03 00:00:00.000' --
GROUP BY (CONVERT (VARCHAR,ALARM_INCIDENT.alarm_local_date,103))


The condition I change in the second query is: "AND (DATEDIFF(ss,alarm_local_date ,first_access_local_date ))<= '60"

Thanks in advance.

J.Pais
Jul 27 '07 #1
1 1206
ilearneditonline
130 Expert 100+
This should do what you want assuming that you have permissions to create stored procedures on the Server.
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE s_first_access_local_date
  2. (@thecount    char(2) -- looks from your query like it should be a char)
  3. AS
  4.  
  5. select (CONVERT (VARCHAR,alarm_local_date,103)) AS DATA
  6. , COUNT (full_clear_opactdisp_id) AS ALARMES
  7.  
  8. FROM ALARM_INCIDENT
  9.  
  10. WHERE (full_clear_opactdisp_id = 'ANL'
  11. OR full_clear_opactdisp_id = 'CAN'
  12. OR full_clear_opactdisp_id = 'CCA'
  13. OR full_clear_opactdisp_id = 'CI'
  14. OR full_clear_opactdisp_id = 'DDC'
  15. OR full_clear_opactdisp_id = 'EA'
  16. OR full_clear_opactdisp_id = 'EPL'
  17. OR full_clear_opactdisp_id = 'FFS'
  18. OR full_clear_opactdisp_id = 'FSA'
  19. OR full_clear_opactdisp_id = 'FTL'
  20. OR full_clear_opactdisp_id = 'MUE'
  21. OR full_clear_opactdisp_id = 'PA'
  22. OR full_clear_opactdisp_id = 'PAS'
  23. OR full_clear_opactdisp_id = 'PJA'
  24. OR full_clear_opactdisp_id = 'PSAE'
  25. OR full_clear_opactdisp_id = 'PSE'
  26. OR full_clear_opactdisp_id = 'SEM'
  27. OR full_clear_opactdisp_id = 'RB'
  28. OR full_clear_opactdisp_id = 'RC'
  29. OR full_clear_opactdisp_id = 'REM'
  30. OR full_clear_opactdisp_id = 'RI'
  31. OR full_clear_opactdisp_id = 'RIC'
  32. OR full_clear_opactdisp_id = 'RPP'
  33. OR full_clear_opactdisp_id = 'RTL'
  34. OR full_clear_opactdisp_id = 'VNR'
  35. OR full_clear_opactdisp_id = 'VR')
  36.  
  37.  
  38. AND (DATEDIFF(ss,alarm_local_date ,first_access_local_date ))<= '@thecount'
  39. AND alarm_local_date > '2007-07-11 00:00:00.000'
  40. --AND alarm_local_date < '2006-05-03 00:00:00.000' --
  41. GROUP BY (CONVERT (VARCHAR,ALARM_INCIDENT.alarm_local_date,103))
  42.  
  43.  
  44. -- call it with
  45. -- exec e_first_access_local_date '30'
Jul 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pete | last post by:
There is a Summary/Example further down... On page one of my site I have a form with some checkboxes and detailed descriptions. When the form is submitted (to page two), the values of the...
4
by: Pete | last post by:
Okay, I'm still stuck with this problem. Here's a quick recap/summary :- 1. Page 1:User checks 3 out of 10 checkboxes and submits form to page 2 2. Page 2:Item count shows 3 items. User checks...
1
by: knoak | last post by:
Hi there, I have a mySQL DB: in it are 5000+ of products, each product has it's own categoryID. The category of a product can be 1 of 5 diferent categories. How do i count in 1 query:...
6
by: Bryan | last post by:
I've been trying to work out a problem but I'm having no luck. I have field in my table for area and I need to count the number of matches and assign a variable for each one.. this is what I have...
3
by: ntg85 | last post by:
Can you use variables in string.count or string.find? I tried, and IDLE gives me errors. Here's the code: while list: print letter = raw_input("What letter? ") string.lower(letter) guess =...
1
by: Puvendran | last post by:
Hi, Can someone please explain the following 1. Meaning of scan count as reported when "statistics io" is turned on prior to running a query. 2. In which situations could you have an...
4
by: ruca | last post by:
Hi, How can I pass the values of some variables from page1.aspx to page2.aspx? I try to define some variables in page2 and then when I click a button in page1 it will fill that variables (in...
3
by: Ivan | last post by:
Thanks to answer topic previous!!!! I use this script to update one table MERGE INTO EIS.CLI_HISTORY TXN USING EIS.CLI_MAPING CLI ON TXN.CLIENTID = CLI.CLIENTID WHEN MATCHED AND...
1
by: jaisi | last post by:
Hi I have a csv file with 3 columns. 1...."bkpf","zr","PDF" 2:.. "bkpf","zq","FAX" Now i have to write a batch program to count the number of pdf files and fax files and watever other...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.