Forum Replies Created

Viewing 15 posts - 871 through 885 (of 1,491 total)

  • RE: How to tune this query

    If myTable is actually a complicated view, try avoiding subqueries and use a derived table instead:

    SELECT T.UID, T.ReferenceNumber, T.Type

    FROM myTable T

    LEFT JOIN

    (

    SELECT DISTINCT T1.ReferenceNumber

    FROM myTable T1

    WHERE T1.ReferenceNumber NOT LIKE 'TR%'

    AND...

  • RE: How to tune this query

    How does this do?

    SELECT UID, ReferenceNumber, Type

    FROM myTable

    WHERE ReferenceNumber NOT LIKE 'TR%'

    AND Type = 1

    UNION ALL

    SELECT T.UID, T.ReferenceNumber, T.Type

    FROM myTable T

    WHERE T.ReferenceNumber NOT LIKE 'TR%'

    ...

  • RE: How to tune this query

    Try:

    SELECT T.UID, T.ReferenceNumber, T.Type

    FROM myTable T

    WHERE T.ReferenceNumber NOT LIKE 'TR%'

    AND

    (

    T.Type = 1

    OR NOT EXISTS

    (

    SELECT *

    FROM myTable T1

    WHERE T1.ReferenceNumber = T.ReferenceNumber

    AND T1.Type = 1

    )

    )

    ORDER BY UID

  • RE: SQL Query help required

    It will probably be more efficient to PIVOT tblCommon_tblSkills.

    Something like:

    ;WITH Skills

    AS

    (

    SELECT Common_ID, [1],[2],[3],[4],[5],[6],[7]

    FROM

    (

    SELECT Common_ID, Skill_ID

    FROM tblCommon_tblSkills

    ) P

    PIVOT

    (

    COUNT(Skill_ID)

    FOR Skill_ID IN ([1],[2],[3],[4],[5],[6],[7])

    ) A

    )

    SELECT C.*

    ,CASE WHEN S.[1] = 1 THEN 'Yes' ELSE...

  • RE: DELETE using JOIN in OLE DB Command transformation gives error when parameters are used

    There is no need for joins with deletes.

    Try the standard ANSI syntax:

    DELETE HouseFacility

    WHERE EXISTS

    (

    SELECT *

    FROM Facility F

    WHERE F.[Id] = HouseFacility.FacilityId

    AND F.FacilityGroupId = ?

    )

    AND EXISTS

    (

    SELECT *

    FROM HouseFacilityGroup G

    WHERE G.[Id] = HouseFacility.HouseFacilityGroupId

    AND...

  • RE: How to use unpivot

    You need to UNPIVOT to get the attribute and then PIVOT to get the attribute values in the same row.

  • RE: How to use unpivot

    The only order in SQL is what is specified in the ORDER BY clause. This means that you will have to some of the work

    in the front end. An UNPIVOT...

  • RE: t-sql SUM

    SELECT lfisno, Stockcode, quantity

    ,CAST(quantity * 1.0 / SUM(quantity) OVER (PARTITION BY lfisno) AS decimal(6,2))AS rate

    FROM

    (

    SELECT lfisno, Stockcode

    ,SUM(quantity) AS quantity

    FROM test

    GROUP BY lfisno, Stockcode

    ) D

  • RE: anyone know a cheap web hosting service that uses ms sql and not mysql

    I would start by downloading, for free, the Express versions of SQL Server and Visual Web Developer from

    http://msdn.microsoft.com

    Then I would look at

    http://www.asp.net

    where there is information to get you started.

    You could...

  • RE: SQL Queries - Parallelism

    To get parallel processing to work, I think you will either have to combine all your queries into one with something like UNION ALL, or write an async CLR SP.

    Also,...

  • RE: Help: How to flatten results

    Use the ROW_NUMBER() function to work out which row the information should be on.

    Also, PIVOT tends to be more readable than lots of CASE statements.

    Try something like:

    SELECT SYear, SWeek

    ,[2] AS...

  • RE: Select on Oracle linked server table.

    The problem may be that all 1.3 million rows are being sent to the MSSQL instance before the filter is applied.

    This could take a long time on a slow link.

    Try:

    1....

  • RE: Performance issue

    On the limited amount of informaton provided, it is difficult to say how to improve the performance.

    The main problem is the CHARINDEX(@query, a.account) > 0, or the equivalent a.account...

  • RE: Is there a more efficient way to write this query?

    On looking at it again, maybe the following:

    SELECT

    CASE

    WHEN N.N = 1

    THEN 'FreeSpace'

    ELSE 'UsedSpace'

    END AS Measurement

    ,CASE

    WHEN N.N = 1

    THEN FreeSpaceMB

    ELSE UsedSpaceMB

    END AS SizeInMB

    FROM

    (

    SELECT FreeSpaceMB, UsedSpaceMB

    ,ROW_NUMBER() OVER (ORDER BY EntryDateTime DESC) AS...

  • RE: Is there a more efficient way to write this query?

    I am not sure what you are trying to do. If you want the latest information for each drive then try something like:

    SELECT fkServerID, DriveLetter, FreeSpaceMB, UsedSpaceMB

    FROM

    (

    SELECT fkServerID, DriveLetter, FreeSpaceMB,...

Viewing 15 posts - 871 through 885 (of 1,491 total)