Combine Insert Into Statements

  • I have 2 insert into statements because the where clauses are different, is it possible to combine them? I would like to have the information within 1 row.

    I can provide data examples as well if needed.

    INSERT INTO dbo.wind0

    (

    datetime

    ) SELECT

    item

    FROM dbo.GA

    WHERE (timeframe = 'actual' and sensor = 'date0' and cat = 'date' and unit = 'utc')

    INSERT INTO dbo.wind0

    (maxspeeddeg)

    SELECT Cast(item as decimal(4,1))as item

    FROM dbo.GA

    WHERE (timeframe = 'alltime' and sensor = 'wind0' and cat = 'maxspeeddir' and unit = 'deg')

  • Hi,

    You mentioned same table, but different columns,

    Post you full table schema with data to understand better.

  • INSERT INTO dbo.wind0

    (datetime, maxspeeddeg )

    SELECT T.item, Cast(S.item as decimal(4,1))

    FROM dbo.GA T

    CROSS JOIN dbo.GA S

    WHERE (T.timeframe = 'actual' and T.sensor = 'date0' and T.cat = 'date' and T.unit = 'utc')

    AND (S.timeframe = 'alltime' and S.sensor = 'wind0' and S.cat = 'maxspeeddir' and S.unit = 'deg')

    Sorry, not tested as no DDL scripts provided.

    _____________
    Code for TallyGenerator

  • SSCarpal Tunnel,

    Thanks for your post. I have used your format to parse the data.

    Thanks again for your help...

    This is a piece to my thesis of setting up a geographic information network end to end.

    Andrew

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply