Forum Replies Created

Viewing 15 posts - 1,126 through 1,140 (of 1,494 total)

  • RE: complex select problem w history tables, date ranges

    Without some sample data it is difficult to tell what you want.

    Maybe something like:

    SELECT U1.UserNew

    &nbsp&nbsp&nbsp&nbsp,D.TelNumber

    &nbsp&nbsp&nbsp&nbsp,D.ChangeDate AS DeviceDate

    &nbsp&nbsp&nbsp&nbsp,D.IMEInew

    FROM DeviceHistory D

    &nbsp&nbsp&nbsp&nbspJOIN (

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspUserHistory U1

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspLEFT JOIN UserHistory U2

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspON U1.TelNumber = U2.TelNumber

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND U1.UserNew = U2.UserOld

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND...

  • RE: Min() Max() and joining fields

    You could try something horrible like:

    DECLARE @TimeFrom datetime

        ,@TimeTo datetime;

    SELECT @TimeFrom = DATEADD(mi, -1, MAX([TimeStamp]))

            ,@TimeTo = MAX([TimeStamp])

    FROM dbo.DemandSpread;

    SELECT

        D1.MinER2BidPrice

        ,D2.MinER2DSTotal

        ,D1.MaxER2BidPrice

        ,D3.MaxER2DSTotal

        ,D1.MinESBidPrice

        ,D4.MinESDSTotal

        ,D1.MaxESBidPrice

        ,D5.MaxESDSTotal

    FROM (

            SELECT MIN(S1.ER2BidPrice) AS MinER2BidPrice

                ,MAX(S1.ER2BidPrice) AS MaxER2BidPrice

                ,MIN(S1.ESBidPrice) AS MinESBidPrice

                ,MAX(S1.ESBidPrice) AS MaxESBidPrice

            FROM dbo.DemandSpread S1

            WHERE S1.[TimeStamp]...

  • RE: Using LIKE

    or you could try something like:

    SELECT *

    FROM YourTable T

        JOIN (

                SELECT '98101' UNION ALL

                SELECT '98104' UNION ALL

                SELECT '98154'

            ) D (ZIP)

            ON T.ZIP LIKE D.ZIP + '%'

  • RE: Sql Query Help

    - The #temp table creates an unique ID for each row in AcctDetails. (Ordered by TransTypeCode)

    - The derived table, D, has the minimum ID for each TransTypeCode. (This is needed...

  • RE: Sql Query Help

    1. As David mentioned, I am not sure why you would want to do this.

    2. Avoid SELECT INTO in production code as it puts schema locks on tempdb.

    3. Avoid loops....

  • RE: Need help in building query

    Umm...

    If the selected mappings can be a subset of the mappings in #tmpmappings, then the following may work. If not, I do not see any alternative but to count.

    SELECT DISTINCT...

  • RE: Need help in building query

    Maybe:

    SELECT D1.ReferenceID

    FROM (

            SELECT M.ReferenceID, COUNT(M.ReferenceID) AS RefCount

            FROM #tmpmappings M

            GROUP BY M.ReferenceID

        ) D1

        JOIN (

                SELECT M1.ReferenceID, COUNT(M1.ReferenceID) AS RefCount

                FROM #tmpmappings M1

                    JOIN #tmpSelectedMappings S1

                        ON M1.MappingTypeID = S1.SelectedTypeID

                            AND M1.MappingID = S1.SelectedID

                GROUP BY M1.ReferenceID

            ) D2

            ON...

  • RE: Complex (to me) SQL Query statement help

    Joe,

    As John indicated, we do not mean any offence but in order to solve the problem we need a 'test bed'.

    Your CREATE TABLE...

  • RE: Complex (to me) SQL Query statement help

    Maybe you should post some correct DDL, some sensible sample data, the results you get and the results you want.

    (If you do this you may even be able to work...

  • RE: Complex (to me) SQL Query statement help

    Maybe:

    SELECT

        T.ittnumber

        ,COALESCE(T.itttitle, T.ittdescription) AS itttitle

        ,T.daterequired

    FROM dbo.tbl3215 T

    WHERE T.completed = 0

        AND COALESCE(T.itttitle, T.ittdescription) IS NOT NULL

        AND EXISTS (

                SELECT *

                FROM dbo.tblassignment A

                WHERE A.ittnumber = T.ittnumber

                    AND EXISTS (

                            SELECT *

                            FROM dbo.tblfltwrkcntr W

                            WHERE W.fltwkcntrid = A.assfltwrkid

                                AND...

  • RE: Query suddenly runs slowly

    As t.PAY_CODE_NUM seems to be an int, it may be worth replacing t.PAY_CODE_NUM IN ('600', '17') with t.PAY_CODE_NUM IN (600, 17) in order

    to stop the implicit conversion. (Might help...

  • RE: Complex (to me) SQL Query statement help

    You may want to consider shortening your nvarchar(max) columns.

    The following may work:

    SELECT

        T.ittnumber

        ,COALESCE(T.itttitle, T.ittdescription) AS itttitle

        ,T.daterequired

    FROM dbo.tbl3215 T

    WHERE T.completed = 0

        AND COALESCE(T.itttitle, T.ittdescription) IS NOT NULL

        AND EXISTS (

                SELECT *

                FROM dbo.tblassignment A

                WHERE...

  • RE: Stored procedure will execute but not save; Visual Studio 2005

    You need to alias the derived table.

  • RE: Sequence of number in a year without an auxiliary table

    On looking at this again, James has a good point about an unique constraint on AA_Anno and Val_NumSpedizione. If you want to add this constraint then try an instead of trigger...

  • RE: Sequence of number in a year without an auxiliary table

    >>>And if the trigger goes in error (for some reason...), the transaction is rollbacked??

    Maybe.

    You need to be careful with transactions. If SET XACT_ABORT is off, as it normally is, then the statement is...

Viewing 15 posts - 1,126 through 1,140 (of 1,494 total)