• dirtyshorellc (8/9/2012)


    My appologies.

    What I am doing is creating a query that will simply take certain columns from a table and export them to a csv file for export to another server. The export is for EMS calls and the data will include all of the unit status information for the incident. All of the other columns that I need to include in this query I'm able to retrieve with no issue. The problem is that I only need 2 types of data from the column I listed and I need to be able to seperate the retrived data and create a seperate column for each data type in the export file.

    Here is what I have so far:

    SELECT

    incident_num AS IncidentNumber, incident_date AS IncidentDateTime, e911_time AS PsapCallDateTime,

    rec_time AS DispatchNotifiedDateTime, disp_time AS UnitNotifiedDispatchDateTime, enr_time AS UnitEnRouteDateTime,

    arv_time AS UnitArrivedSceneDateTime,

    -- This is where the CAD_COMMAND_CODE for UnitLeftScene and PatientArrivedDest fields will live.

    clr_time AS UnitBackInServiceDateTime, location AS StreetAddress, address AS StreetAddress2,

    city_code AS City, call_type AS EmdCardNumber, disposition_code AS DestinationCode

    FROM

    cfs_incident_core

    As you can see I am aliasing each column of the table to match the expected format for the other server.

    Also I seem to have made a mistake in my first post. Each query should have a different Alias. The query for the 'AH' data should have been aliased as PatientArrivedDestDateTime. Again my apologies!

    Also I'm using MS SQL SVR 2000.

    Perhaps something like this?

    SELECT unit_status

    UnitLeftSceneDateTime=MAX(CASE WHEN cad_command_code = 'EH' THEN unit_status_datetime END)

    PatientArrivedDestDateTime=MAX(CASE WHEN cad_command_code = 'AH' THEN unit_status_datetime END)

    FROM unit_status_hist

    GROUP BY unit_status


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St