Forum Replies Created

Viewing 15 posts - 781 through 795 (of 1,494 total)

  • RE: GROUP BY, PARTITION?

    The following will order the compsite alphabetically but it will have an unique value:

    ;WITH Composites

    AS

    (

    SELECT A.ColA, A.ColB

    , STUFF(

    (SELECT ' ' + CAST(B.ColC as varchar(255)) + ','

    FROM YourTable B

    ...

  • RE: “SELECT 1? rather than a “SELECT *” when using an EXISTS or a NOT EXISTS clause”.

    In Theory, it makes no difference what you SELECT in an EXISTS sub-query as it is just syntactical sugar. (ie Nothing is actually selected.)

    I seem to remember someone doing a...

  • RE: sub select

    You need to give the columns in a derived table a name so do something like:

    SELECT COUNT(*)

    FROM

    (

    SELECT UPPER(s_name) AS s_name

    FROM bmi_tr

    ) dual;

    or:

    SELECT COUNT(*)

    FROM

    (

    SELECT UPPER(s_name)

    FROM bmi_tr

    ) dual (s_name)

    Of course, you will...

  • RE: Backup: My logfile is very large!

    amenjonathan (2/4/2011)


    After a full or log backup, the transaction log will be emptied out, but the log size remains.

    The log file is only emptied after a log backup.

    So:

    1. Schedule log...

  • RE: Delete Duplicate Records

    Maybe:

    ;WITH AttemptOrder

    AS

    (

    SELECT *

    ,ROW_NUMBER() OVER (PARTITION BY CODE, FAMILY, DEVICE, MANUFACTURER ORDER BY ATTEMPTS DESC) AS RowNum

    FROM codes_table

    )

    DELETE AttemptOrder

    WHERE RowNum > 1

  • RE: Query Help - Denormalising Perhaps ?

    I would test both solutions and see which is most efficient with your data.

  • RE: How to convert integer to hours,mins and seconds

    Why bother with functions?:

    DECLARE @starttime int = 80010

    ,@endtime int = 161500

    SELECT ((@endtime/10000 * 60) + (@endtime%10000/100))

    - ((@starttime/10000 * 60) + (@starttime%10000/100))

  • RE: Query Help - Denormalising Perhaps ?

    Just do another self join and sort it from there.

    Something like the following:

    DECLARE @DefaultMoisture float = 15.0

    ,@DefaultCu float = 2.0;

    WITH ShiftTonnageMoistureCu

    AS

    (

    SELECT S.[LogTime] AS ShiftTime

    ,S.Value AS WetTonnage

    ,COALESCE(AVG(M.Value), @DefaultMoisture) AS MoistureP

    ,COALESCE(AVG(C.Value), @DefaultCu)...

  • RE: How to convert integer to hours,mins and seconds

    Maybe:

    DECLARE @time int, @dt datetime;

    SET @time = 80010;

    SET @dt = DATEADD(second, 80010%100,DATEADD(minute, 80010%10000/100,DATEADD(hour, 80010/10000,'19000101')));

    SELECT @dt

  • RE: Query Help - Denormalising Perhaps ?

    A CTE, except for the special case of recursion, behaves just like a non-persisted view that can only be used in the currect statement.

    ie Just think of a CTE as...

  • RE: Query Help - Denormalising Perhaps ?

    A self join should work.

    Something like:

    -- *** Test Data ***

    CREATE TABLE #t

    (

    [TimeStamp] datetime NOT NULL

    ,IDNumber int NOT NULL

    ,Value decimal(19, 2) NOT NULL

    ,Period varchar(2) NOT NULL

    )

    INSERT INTO #t

    SELECT '20110115 07:00:00', 33080,...

  • RE: Help On Query

    Try something like:

    SELECT *

    FROM Client C

    JOIN [Address] A

    ON C.ClientID = A.Address_ClientID

    LEFT JOIN

    (

    ITReturn R

    JOIN

    (

    SELECT R1.ITR_ClientID, MAX(R1.AssesmentEndYear) AS AssesmentEndYear

    FROM ITReturn R1

    GROUP BY R1.ITR_ClientID

    ) D

    ON R.ITR_ClientID = D.ITR_ClientID

    AND R.AssesmentEndYear = D.AssesmentEndYear

    )

    ON C.ClientID =...

  • RE: problem with trigger

    You could also have some problems with the data if you are not handling exceptions correctly.

    (eg Attempting to put NULLs into a NOT NULL column etc)

    You could try logging any...

  • RE: Return most recent result or a default

    I would be inclined to look at:

    1. Just using union all for the default result set:

    SELECT TOP (1)

    {actual field list}

    FROM {same as EXISTS statement}

    WHERE {same as EXISTS statement}...

  • RE: Query in Sql 2000

    Google Number/Tally table.

Viewing 15 posts - 781 through 795 (of 1,494 total)