CASE in SQL Server statement

I'm working on a project for ambulance response times. In the following query, which is in my coldfusion code, I use a CASE statement on a subquery to count of ambulance response times in stores. An ambulance should arrive at an incident of emergency in less than 08:59 (539 seconds), otherwise it is considered to be late. In my coldfusion Transact-SQL code, I am:
1.) is a subquery.
2.) counting "number of events"time-based, it took the ambulance to arrive. "
3.) only count the ambulances of Lee County and excluding A6 type (non-emergency) calls.
(4.) grouping of date parts.

SELECT DATENAME ("M", I.I_tTimeDispatch) in the month, (DATEPART ("yyyy", I.I_tTimeDispatch)) AS year,.
COUNT (CASE WHEN (DATEDIFF ("S", I.I_tTimeDispatch, I.I_tTimeArrival)) BETWEEN 0 AND 539 SO evnt END) AS OnTime.
COUNT (CASE WHEN (DATEDIFF ("S", I.I_tTimeDispatch, I.I_tTimeArrival)) BETWEEN 540 AND 1028 THEN evnt END) AS of late.
COUNT (CASE WHEN (DATEDIFF ("S", I.I_tTimeDispatch, I.I_tTimeArrival)) > 1028 THEN evnt END) AS aberrant
(SELECT I_EventNumber AS evnt, I_tTimeDispatch, I_tTimeArrival, I_kTypeInfo, I_Agency FROM dbo. IIncident) as I
INNER JOIN dbo. ITypeInfo AS T ON I.I_kTypeInfo = T.ITI_TypeInfo_PK
WHERE I.I_Agency = 'LC'
AND T.ITI_TypeID NOT LIKE ' A6. "
GROUP BY (DATEPART ("M", I.I_tTimeDispatch)), (DATENAME ("M", I.I_tTimeDispatch)), (DATEPART ("yyyy", I.I_tTimeDispatch))
ORDER BY (DATEPART ("yyyy", I.I_tTimeDispatch)) ASC, ASC (DATEPART ("M", I.I_tTimeDispatch))

Here's my problem!
I go in Microsoft Access to check my stats and I get different counts. For example, in April 2008, my coldfusion query returns 3 944 response ambulance in time. My query Access for the same period of time, using only ambulances in Lee County and excluding non A6-emergency returns only 3 805 answers. There is an undercounting of 139 responses. Even for my other tanks of the time, I get a undercount.

Here is my SQL Access to the tray of response time (< seconds 539 or 08:59):

SELECT Count (dbo_IIncident.I_EventNumber) AS CountOfI_EventNumber
FROM dbo_IIncident INNER JOIN dbo_ITypeInfo ON dbo_IIncident.I_kTypeInfo = dbo_ITypeInfo.ITI_TypeInfo_PK
WHERE (((dbo_IIncident.I_Agency) = "lc") AND ((dbo_ITypeInfo.ITI_TypeID) not as ' a6 * ') AND ((dbo_IIncident.I_tTimeDispatch) between # #4/1/2008 and may 1, 2008 #) AND ((DateDiff ("s", [dbo_IIncident].) [I_tTimeDispatch], [dbo_IIncident]. [I_tTimeArrival])) Between 0 and 539));

How two queries that are supposed to do the same could return different results?


In order to dispel any confusion, I write the page temporarily. Please look at because it can help you visualize the problem.
http://lcfcfn01/secure/GTandLT_8_59.cfm

Instead of counting, why don't you change your SQL to list the incidents in the two queries instead, then you can see who is included in the T - SQL that are not captured in Access code.

Phil

Tags: ColdFusion

Similar Questions

  • How to send the SQL for SQL Server statement and return data without using database connectivity Kit?

    Hi, I tried to figure out how to extract data from my SQL Server databases and reading messages and to do some tests with examples, I can get data connection type in my SQL server, but so far nothing helps.  Is it possible to get data from a SQL Server database without using the database connectivity Toolkit?  and if so, how?  are there whitepapers and/or examples of this?  So far, I can't find something that works.  Thank you.

    Jesse - what is your reason for not using the database connectivity Toolkit? It is by far the best way to recover the data.

  • Connection failed SQL State 08001 SQL Server Error 10061 SQL Native Client TCP provider no. could be made because the target machine actively refused it

    Wandering SQL Native Client Datasource - apparently, it's a pretty common problem and I see several resolutions to it.  This problem started for our long company until I started working here.  We do not allow remote connections.  JDE Enterprise Server and SQL server are on the same subnet.  Users are on a different subnet.  SQL Server gets this message tries to connect to the Server Enterprise JDE:

    Connection failed: State 08001 ' SQL': SQL Server Error 10061: Microsoft SQL Native Client TCP provider: no connection could be made because the target machine actively refused it.

    I tried several suggested solutions and do not get the case. Any help is appreciated. Thank you, Sophie

    Hello

    The issue of Windows XP, you have posted is better suited for the IT Pro TechNet public. Please ask your question in the SQL Serversupport for assistance.

    Hope the helps of information.

    Concerning
    Joel S
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • State SQL 28000 and SQL Server error 18452

    I have a SQL 2000 Server on a server with Windows Server 2003 computer.

    I have a laptop with Windows Vista, for which we are unable to connect to the database and it gives an error 24000 state SQL and SQL Server error 18452 with description as "failed to connect to the user (null). Reason: Not associated with approved connection SQL server.

    Please provide a solution to this problem.

    Thank you

    Hello

    Questions like these are much better handled in the TechNet IT Pro Forums.

    My moderator tools cannot transfer messages on Windows forums, please re - ask you question there.

    http://social.technet.Microsoft.com/forums/en-us/category/SQLServer/
    Jack - Microsoft MVP, Windows networking. WWW.EZLAN.NET

  • SQL Server problem at startup - States of error SQLEVN70. RLL corrupt... How do I uninstall this driver & run Setup again?

    This error appears only in the beginning upward... I can clear the error by pressing close. It does not seem to cause any problems with any of my applications, but it is annoying when I turn on my computer and this error message. Your help would be appreciated if someone can give me the steps to correct this.

    Hello

    The problem is with SQL server, I suggest you to send your request from the link and check.

  • 7 Microsoft SQL Server 2005 Express Edition SP3 (KB955706) __Pour Windows 7 "Windows Update_0000041D" "Windows Update_dt000".

    Not udating error 41 d Windows 7 Professional "Windows Update_0000041D" "Windows Update_dt000 SQLEXPR32. Article from the Base of the 955706 EXE

    Please help to States, it is essential to have this udated

    Hi RTsheba,

    Your computer is on the field? If so, you probably haven't privileges to download and install Microsoft SQL Server 2005 Express Edition Service Pack 3 (KB955706)

    In most cases, these errors are caused by temporary problems caused by very slight interruptions in communications between the computer to update and the update to download. These questions are usually self-healing. So, before you try the troubleshooting, I suggest you follow the suggestions below.

    Suggestion 1:

    Temporarily disable all security software and try to download the update. Follow the steps mentioned below

    http://Windows.Microsoft.com/en-us/Windows7/turn-Windows-Firewall-on-or-off

    http://Windows.Microsoft.com/en-us/Windows7/disable-antivirus-software

    Note: Allow all security software after downloading and installing the update.

    Windows update General troubleshooting

    The following describes how do to stop the services related to the update of Windows, rename system folders, save the associated DLL files and then restart the services mentioned previously. This diagnosis is generally applied to all Windows Update related issues.

    Suggestion 2:

    Stop Windows Update services

    1. click on start, click principally made programs, accessories, right-click on command prompt and select run as administrator.

    2. If you receive a user account control notification simply click on continue.

    3. at the command prompt, type the following commands and press ENTER after each command.

    net stop wuauserv
    net stop bits

    net stop cryptsvc

    4 Please, do not close the command prompt window.

    Proposal 3:

    Rename Windows Update records

    1. at the command prompt, type the following commands and press ENTER after each command:

    2 ren %systemroot%\System32\Catroot2 Catroot2.old

    3 ren %systemroot%\SoftwareDistribution SoftwareDistribution.old

    4 Please, do not close the command prompt window.

    Aziz Nadeem - Microsoft Support

  • Why odi creates datetime2 (27) type of data and because of create table in sql server 2012 is a failure

    Hey

    I had a situation in the present case, I flat file and I want to load it into sql server 2012.

    In the flatfile I have 2 data types of columns date and I chose LKM FILE TO SQL, when I try to run it fails to create the work table.

    When I c the code in this step it shows

    create the table dev.dbo.C$ _0TES

    (

    ASN_BOL_NBR NUMERIC (7,0) NULL,

    ASN_CARTON NUMERIC (20.0) NULL,

    ASN_SHORT_SKU NUMERIC (7,0) NULL,

    ASN_SKU_CHECK_DIGIT NUMERIC (1.0) NULL,

    ASN_DESC VARCHAR (25) NULL,

    ASN_QUANTITY NUMERIC (7,0) NULL,

    ASN_LEAVE_DATE DATETIME2 (27) NULL,

    ASN_ARRIVAL_DATE DATETIME2 (27) NULL,

    ASN_MULT_PACK VARCHAR (1) NULL,

    ASN_MULT_SKU VARCHAR (1) NULL

    )

    MSG 1002, level 15, State 1, line 9

    Line 9: Specified scale 27 is not valid.

    DATETIME2 (27) the table of creative work is a failure because of the type of data

    ASN_LEAVE_DATE DATETIME2 (27)

    ASN_ARRIVAL_DATE DATETIME2 (27)

    Is there a way to avoid a DATETIME2 (27)?

    Thank you!

    Yes, I would certainly put the data on the source of the string type.

    Then in your mapping/interface, you can use the CONVERT function.

    For example, CONVERT (DATETIME, YOUR.) ASN_LEAVE_DATE, 101)

    In this example, 101 as a style means that your file contains a date in the format dd/mm/yyyy.

    See CAST and CONVERT (Transact-SQL) to find out what style you apply.

    Kind regards

    JeromeFr

  • Oracle and SQL server database

    Hello

    Is there another way to directly see the data stored in the oracle database or I can see it only through an external tool such as SQL Server?

    Thank you

    J

    997282 wrote:
    Hello

    Is there another way to directly see the data stored in the oracle database or I can see it only through an external tool such as SQL Server?

    Thank you

    J

    What do you mean by "an external tool such as SQL Sever"?
    SQL Server is Microsoft's RDBMS product.

    Oracle data files are in a binary format that is known only to Oracle. (Like SQL Server data files are in a binary format known only to Microsoft). Unless you're talking about a binary dump, they can be "seen" by the published interface that is used by all clients. In the case of Oracle, these customers would include sqlplus and a multitude of third-party products, as well as programming languages that can make calls to the oracle SQL Developer interface. And in all cases, he will eventually return to pass SQL statements.

    What is your goal?

  • Moved from vCenter 4.0 Db to new MS SQL server - event task Cleanup job

    Last week, we have moved our vCenter 4.0 Db to a new MS SQL Server and instance. I just stopped by VMware, our DBA moved the Pb services, and I've updated the ODBC settings, restarted the services and everything worked FINE.

    However, today my DBA says:

    Below the jobs were provided on:

    Event task cleaning VM_SACWIS_TEST

    Last day stats rollup VM_SACWIS_TEST

    Last month stats rollupVM_SACWIS_TEST

    Spent the week stats rollup VM_SACWIS_TEST

    I asked the method he used to move the DBs and expect from him. I don't think that the DB UpdateManager gave us all grief...

    Thank you.

    (A special "Hi" to David w. in Chicago, my Professor VCP)...

    If the old DB server is always available, you can move tasks SQL Agent Jobs, too.  If this isn't the case, you probably need to re-create.

    http://KB.VMware.com/kb/1004382

  • How to upgrade from Virtual Center 2.5 + SQL Server 2000 to vCenter 4.1 + SQL Server 2008 (R2)?

    I plan the upgrade of an existing VMware Infrastructure 3 (Virtual Center 2.5 + ESX 3.5) to vSphere 4.1, and I'm stuck in the Virtual Center Server upgrade and its back-end database.

    vSphere 4.1 is released only as a 64-bit software, so he needs a x 64 O.S.; This excludes an upgrade the existing server on-site.

    The plan is to install a new Server Windows Server 2008 R2 with SQL Server 2008 (or 2008 R2 if taken in charge), migrate the database and install 4.1 on the server vCenter.

    The question: How can I migrate the database?

    When you perform an upgrade of Virtual Center vCenter 4.0 on-site, the database is automatically upgraded; but this isn't the case when you install a new server.

    VMware provides a utility to clear the existing database and import it into a new server, but it works only for SQL Server Express (which according to VMware must not be used in medium/large production environments); If this is not an option.

    I am unable to find a support procedure to perform this migration.

    Can someone please help?

    Massimo,

    I just went through it and found it to be a little pain simply because I forgot to VMware document simplicity...

    You are right, the 'migration' tool does support SQL Server Express, I don't know why and niether are the two VMware Tech Support Agents I spoke with.

    To anyone reading this. NOTE If you perform the upgrade / migration SQL Server Express via the Migration tool you MUST check the registry DbServerType key FIRST! If it is set on Custom Migration tools will ignore simply stages of database! See this VMware KB article for more information:

    http://KB.VMware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalID=1024380

    Yes, it is the States 'failure', what he does not say, it is that the Migration tool will be 'Silencieusement Skip' your database.

    End of Migration tools do call a standard SQL Server T - SQL backup command. YAY! You don't have to upgrade your existing 32-bit vCenter Server, do first just in case backup/snapshot, then run through the upgrade as if you were going to use the 32-bit version in production. This step will apply to any database schema change.

    Build your brilliant new 64-bit server, install all of the bits and then use SQL Server Management Studio to make a backup of SQL Server 32-bit database and then restore it on your new 64-bit server. NOTE: Make sure that all SQL and vCenter services are stopped before proceeding with the backup and restore of the measures.

    After the restoration of the SQL on your new server it reboot and everything will come back to life just as it is only now with all 64 bit!

    Hope this Helps!

    Bill Hilburn, Senior Systems Engineer

    StoneAge, Inc.

    http://StoneAgeTools.com

  • Backup SQL server using VCB

    Hi, I want to look for opportunities to save a virtual machine that will run SQL server for sharepoint. I am familiar with virtual machines VCB backups, but in this case the SQL database will not be in a consistent state for the snapshot VCB virtual machine takes place.

    What are the options here can I back up this database SQL using VCB?

    Thank you, Mark

    Yes it is possible, but that's really all depends on your needs for the consistency of the data.  The other option is to get your consistent data before the backup, but there may be a lot of logistical problems around that.  Things like ALS and downtime for backups don't usually go together well.  Again, the requirements of consistency are why I prefer SQL clients agents or a flat SQL backup file.

  • Oracle 10.2 64-bit to SQL Server 2000 (32-bit) through DG4ODBC and DBLINK

    Hi all

    I need to connect from Oracle to SQL Server through DB-LINK, and since my installation Oracle does not contain of HSODBC, I installed DG4ODBC.

    My current setup SW is:

    (1) oracle Server (64-bit):
    Operating system: Windows Server 2008 Standard SP2
    DB: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production 64-bit
    Gateway: Heterogeneous Agent 11.2.0.1.0 - 64 bit Production version built with Oracle Database Gateway for ODBC
    Oracle home: E:\oracle\product\10.2.0\db_1\
    Gateway home: D:\apps\product\11.2.0\tg_1\
    In addition, he performs a 10.0 ArcGIS/ArcSDE on Oracle.

    (2) MS SQL Server (32-bit):
    OS: Windows NT 5.2 SP2
    DB: Microsoft SQL Server 2000-8.00.2065 (Intel X 86)

    There are two headphones running (one of each installation, 10.2 and 11.2) which, I suppose, can lead to conflicts or reduce performance. As a restriction, I need the listener from 10.2 to continue

    unchanged running from ArcSDE Service use and re-create them is a pain.

    So my question is, how do I configure a (10.2) or two listeners (10.2 and 11.2) use DG4ODBC to connect to a remote SQL Server to Oracle?

    I have followed several threads in this forum, try different configurations but I can not connect successfully with the DATABASE LINK. In most cases, I get error ORA-28545 and ORA-02063.

    Can someone help me solve this problem? What I need to send more information, for example {SID} init. now, listener.ora, tnsnames.ora, clarifications etc?

    Thank you much in advance.

    Gaston.

    Hi, Gaston,.
    The following note describes the setting up Dg4ODBC on 64-bit Windows-

    How the installer DG4ODBC (gateway for ODBC Oracle database) on 64-bit Windows operating systems (Doc ID 1266572.1)

    You definitely need 2 separate listeners - one for the 10.2 RDBMS and one for the 11.2 Dg4ODBC. There should be no concern about the performance or other conflicts. The only thing to know is that listener DG4ODBC must use a different port than the 10.2 listener.

    Heike referred to as using a file odbc.ini, but it is necessary when setting up Dg4ODBC on Unix/Linux platforms. Under Windows, the database non-Oracle information in the system DSN that is used for the HS_FDS_CONNECT_INFO parameter in theinit .ora file DG4ODBC.

    Do the following-

    -Configure the gateway as Note 1266572.1 with a listener running of the ORACLE_HOME bridge, in your case D:\apps\product\11.2.0\tg_1\
    -create tnsnames.ora entry in the 10.2 RDBMS directory $ORACLE_HOME/network/admin for the gateway
    -create the database link in the RDBMS using the tnsnames.ora entry.

    If you still have problems then view the files following and information-

    -Gateway listener.ora
    -gatewayinit .ora
    -RDBMS tnsnames.ora
    -create database link statement

    Another point, because you're running on Windows 64 bits, then the ODBC driver that is referred to in the system DSN for the connection must be a 64-bit driver. You cannot use the 32-bit drivers with 64-bit DG4ODBC.

    Kind regards
    Mike

  • Binary search in SQL Server 2008?

    I learned recently from binary search in one of my classes at school, and he raised a question in my head on access to a database using Coldfusion.  Lets say I create a table in MS SQL Server 2008, and I attribute table 'id' column, either the primary key auto increment.  If I make the statement SELECT coldfusion * FROM MaTable WHERE id = "idOfRow", would be a binary search in this case since are the ID in a sorted order?

    Thank you

    Ben

    Oh yes, properly indexing your tables based on the way you access your data is almost always the fruit hanging low for the optimization of the database.  The concept lacks your previous statement is probably the primary key index only is never needed.  But if 95% of your access is really based on a field of unique key indicate, then it is probably enough for your needs today.

    But as you start to work with more complex data, we must be sure to understand the other indexing options provided by the robust database management systems.

    Just don't worry your head on the way which the index actually work under the hood.  Just trust that some very intelligent people have put a lot of time so that they work very well indeed.

  • Migration sql server 2000 for oracle 9i

    Hello

    I migrate from sql server 2000 to oracle 9i

    When I capture Microsoft Sql Server, it gives an error
    oracle.dbtools.metadata.persistence.PersistenceException: ORA-04098: trigger ' MIGRATION. MD_PROJECTS_TRG' is invalid and does not re-validation
    I try again and it starts but it's not to stop until clicking on cancel or close

    What's the harm?

    Thank you

    Hello
    You hit a known issue using a repository created in 9.2.
    To show that this is the case do the following-

    SQL > alter trigger compilation MD_PROJECTS_TRG.

    WARNING: Trigger modified with compilation errors.

    SQL > show errors
    Errors for MD_PROJECTS_TRG TRIGGER:

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    3/9 PL/SQL: statement ignored
    3/20 PLS-00905: object MIGREP. MD_META is not valid

    Compilation md_meta-

    SQL > alter compilation package md_meta;

    WARNING: The package has been modified with compilation errors.

    SQL > show errors
    PACKAGE MD_META for errors:

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    0/0 PLS-00908: the stored format of MD_META is not supported by this
    Release

    21/4 PLS-00114: identifier 'PUTBAIFZKA3IHSJ5AC4ZXWYAWG41KN' too long
    21/4 PLS-00707: construction not taken in charge or internal error [2702]
    SQL >
    ==

    If you get this, so the only alternative is to create the SQL * Developer repository in a database of 10.2.

    Kind regards
    Mike

  • Import Access DB to SQL Server

    I'm trying to set up a SQL Server database.

    Currently I use Access and my own plan which is very close to the "generic" Recordset

    I tried several things.

    * Band my .mdb so that it contains only the tables but no data.

    * Import to SQL Server.

    * Database .mdb complete, including the import data.

    My tablenames in SQL Server always gets the prefix 'dbo '. This means that they use a schema "dbo" - right?

    Can I export my plan (.ini) TestStand, , but how do I get that in SQL-SERVER?

    Currently, I get the error below: (what is the result of not having the correct implement schema?)

    An error occurred calling "LogMultipleResults" in "ITSDBLog" of "ZNIUGOL TestStand database logging"

    An error has occurred by executing a statement.

    Statement: UUT_RESULT.

    Description: Cannot insert the value NULL in the column 'ID', table 'PTA_DR2_COMMON.dbo.UUT_RESULT '; column does not allow NULL values. INSERTION fails.

    Number:-2147217873

    NativeError: 515

    SQLState: 23000

    Reported by: Microsoft SQL Server Native Client 11.0Description: the statement has been terminated.

    Number:-2147217873

    NativeError: 3621

    SQLState: 01000

    Reported by: Microsoft SQL Server Native Client 11.0Description: operation errors generated several OLE DB steps. Check each OLE DB status value, if available. No work has been done.

    Number:-2147217887

    NativeError: 0

    SQLState: 01000

    Reported by: Microsoft SQL Server Native Client 11.0

    Under the 'data link property"in TestStand I've set up to use a"specific name and user password"which is implemented in SQL Server.

    I choose to save the "Password."

    Test the connection is OK.

    If I close the window, but right after the reopening, the password properties are gone... which means it is not saved!   Why?

    If I use NT integrated security, access to the database works.

    I found a 'Solution' by exporting each table access rather than import it on SQL Server.

    Now, it seems to be OK

Maybe you are looking for

  • Install location Services stopped with fresh 10.11.4

    I performed a clean installation of 10.11.4 to find that location Services are no longer available (maps, weather, System Services). I have enabled "enable location services" walking several times in an attempt to activate the service, but still no j

  • HP Pavilion g7: new hard drive; can I reinstall Windows?

    Go mobile g7 of a parent, I bought for her a few years; but the hard drive is a mess, (I can't understand how to wipe or format... etc... loads of shit, malware, etc., etc.) Hell with all that, if I will just get the hard drive and install. better to

  • LabVIEW 8.6.1 crashes with screws built in LabVIEW 7.1.1

    Hi experts, We have recently upgraded to latest LabVIEW 8.6.1. Told us that screws built in 7.1.1 will be open in 8.6.1 without any pain, but that seems to be not right. We have a big software test built in 7.1.1 and locks up when I try to open it wi

  • Subsystem spooler stopping constantly

    When I start the system on that I get a message the Spooler subsystem stopped and was closed by windows.  I can't print and even when you start the print spooler stops as soon as I try to print. How can I fix this spooler?

  • Windows 7: memory setting

    Windows7: Photos images program says that she didn't have enough memory to complete the registration of a file (required at least 300 dpi).  With 8 GB of system memory, 1 terabyte HD... I need to know how to set the parameter memory.  Need basics lik