• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "Help with a simple SQL2005 stored proc"

Collapse

  • wxman
    replied
    Great, this looks good - I have will have a fiddle after the Forest / Chelsea match.

    Thnaks for taking the time to reply

    Leave a comment:


  • dang65
    replied
    I'm not a DBA so there's probably a much more elegant way than this, but maybe you could try:

    1. Declare variables for each of the values you want:

    declare @AirTempHi varchar(50)
    declare @AirTempHiDate datetime
    declare @AirTempLo varchar(50)
    declare @AirTempLoDate datetime


    etc

    2. Include all the columns in the temporary table:

    create table #AllEmployees
    (
    AirTempHi varchar(50),
    AirTempHiDate datetime,
    AirTempLo varchar(50),
    AirTempLoDate datetime
    ... and so on
    )

    3. Get the values for each variable:

    SELECT TOP 1 @AirTempHi = AirTemp, @AirTempHiDate = importTime FROM WxSTNData
    ORDER BY AirTemp DESC


    etc

    4. Once you've got all the values then do one insert into the temporary table:

    INSERT INTO [dbo].[#tempRecords]
    (AirTempHi, AirTempHiDate, AirTempLo, AirTempLoDate)
    values(@AirTempHi, @AirTempHiDate, @AirTempLo, @AirTempLoDate)


    etc

    5. Then do one select on the final temp table contents, as in your version.

    I'm not certain of all the syntax, but it's something like that anyway.

    Leave a comment:


  • wxman
    started a topic Help with a simple SQL2005 stored proc

    Help with a simple SQL2005 stored proc

    This is a home project (not work related) that is driving me nuts!!

    I am trying to select all my all time weather records from my database so that I can display them on a “all time weather records page”..

    I can grab all my weather all time records from my database via simple multiple select statements and then insert these into a table – but they end up as

    9.8 2007-01-27 13:26:00
    8.7 2007-01-27 14:53:00
    17 2007-01-27 13:51:00
    1031.3 2007-01-27 13:23:00
    1031.0 2007-01-27 14:01:00
    10.0 2007-01-27 13:23:00
    7.2 2007-01-27 13:51:00
    0.0 2007-01-27 13:23:00
    421 2007-01-27 13:25:00

    What I really want is the records returned on a single row I.E.

    AirTempHi, AirTempHiDate, AirTempLo, AirTempLoDate etc..

    Can anyone point me in the right direction? – Here is my storedProc ..

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author: <Author,,Stuart Robinson>
    -- Create date: <Create Date,20070127>
    -- Description: <To be Used with ByLink.com - Records.aspx
    -- =============================================
    ALTER PROCEDURE [dbo].[spu_GetWxSTNRecords]

    AS
    BEGIN
    SET NOCOUNT ON;

    CREATE TABLE [dbo].[#tempRecords](
    [Reading] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
    [ReadingDate] [SmallDateTime] NULL,
    ) ON [PRIMARY]

    INSERT INTO [dbo].[#tempRecords]
    SELECT TOP 1 AirTemp AS AirTempHi, importTime AS AirTempHiDate
    FROM WxSTNData
    ORDER BY AirTemp DESC

    INSERT INTO [dbo].[#tempRecords]
    SELECT TOP 1 AirTemp AS AirTempLo, importTime AS AirTempLoDate
    FROM WxSTNData
    ORDER BY AirTemp

    INSERT INTO [dbo].[#tempRecords]
    SELECT TOP 1 WindG, importTime AS WindGHiDate
    FROM WxSTNData
    ORDER BY WindG DESC

    INSERT INTO [dbo].[#tempRecords]
    SELECT TOP 1 SLP AS SlpHi, importTime AS SlpHiDate
    FROM WxSTNData
    ORDER BY SLP DESC

    INSERT INTO [dbo].[#tempRecords]
    SELECT TOP 1 SLP AS SlpLo, importTime AS SlpLoDate
    FROM WxSTNData
    ORDER BY SLP

    INSERT INTO [dbo].[#tempRecords]
    SELECT TOP 1 GTemp AS GTempHi, importTime AS GTempHiDate
    FROM WxSTNData
    ORDER BY GTemp DESC

    INSERT INTO [dbo].[#tempRecords]
    SELECT TOP 1 GTemp AS GTempLo, importTime AS GTempLoDate
    FROM WxSTNData
    ORDER BY GTemp

    INSERT INTO [dbo].[#tempRecords]
    SELECT TOP 1 UV AS UVHi, importTime AS UVHiDate
    FROM WxSTNData
    ORDER BY UV DESC

    INSERT INTO [dbo].[#tempRecords]
    SELECT TOP 1 Solar AS SolarHi, importTime AS SolarHiDate
    FROM WxSTNData
    ORDER BY Solar DESC

    SELECT * from [dbo].[#tempRecords]
    DROP TABLE [dbo].[#tempRecords]
    END
Working...
X