Forum Replies Created

Viewing 15 posts - 316 through 330 (of 1,229 total)

  • RE: making records unique

    ChrisM@Work (9/12/2013)


    What results do you get from this query?

    ;WITH Deleter AS (

    SELECT

    ID,

    rn = ROW_NUMBER() OVER(ORDER BY Postcode,BuildingName,housenumber,SubBuilding,County,Town,

    LocalName,PostOutCode,PostInCode,Throughname,Throughdesc,poboxno,BusinessName,locality)

    FROM PostCodesAndAddressesBt

    )

    SELECT *

    FROM Deleter

    WHERE rn > 1

    I think he...

  • RE: How to Group by the Past Seven Days

    garyh2k3 (8/13/2013)


    My spreadsheet has sample data of grouped by month, grouped by Day. I would like the same date displayed for the group by the past 7 days. ...

  • RE: How to Group by the Past Seven Days

    Which post, Gary?

  • RE: Alternate of materialized view to avoid excessive table reads where Min/Max is required

    Post the actual execution plan for the query as a .sqlplan attachment.

  • RE: T-SQL Function that works like the FIRST funcion in MS Access?

    Could it be as simple as this?

    SELECT

    s.Space_Number,

    MIN(e.First) AS First1,

    MIN(e.Last) AS Last1,

    MAX(e.First) AS First2,

    MAX(e.Last) AS Last2,

    MIN(e.CC) AS FirstOfCC,

    MIN(e.[Employee Type]) AS [FirstOfEmployee Type],

    s.[Space Type]

    FROM...

  • RE: Indexing a view

    Chris, can you post the CREATE VIEW statement? Better still, can you post an actual execution plan (as a .sqlplan attachment) of a select from the 'slow' view?

  • RE: Is overpunch amenable to cross apply?

    SELECT

    NDCNumber,

    IngredientCost = CAST(CASE

    WHEN Trailer IN ('{','A','B','C','D','E','F','G','H','I')

    THEN LEFT(ingredientcost,LEN(ingredientcost)-1)

    + CAST(CHARINDEX(Trailer,'{ABCDEFGHI')-1 AS VARCHAR(1))

    WHEN Trailer IN ('J','K','L','M','N','O','P','Q','R','}')

    THEN '-' + LEFT(ingredientcost,LEN(ingredientcost)-1) + '1'

    END AS MONEY)/100

    FROM ...

    CROSS APPLY...

  • RE: Help with the query and index.

    mayurkb (8/9/2013)


    ScottPletcher (8/9/2013)


    You don't need separate indexes on StartDateTime and EndDateTime, you need them in the same index.

    SQL will only be able to do a seek on that index if...

  • RE: Query Help - Sum by Month

    Stefan_G (8/7/2013)


    A little challenge:

    Assume there is a clustered index on the date column.

    Can you create a query that exploits the clustered index to achieve even better performance?

    Back to you, Stefan....

  • RE: select DISTINCT cost too high?

    -- sample data

    DROP TABLE #CSV_Details_MainFile

    CREATE TABLE #CSV_Details_MainFile (GA_Drg_NO VARCHAR(25), Rev_NO CHAR(1), Mark_No VARCHAR(3), mark_rev_no VARCHAR(3), DeleteFlag CHAR(1))

    INSERT INTO #CSV_Details_MainFile (GA_Drg_NO, Rev_NO, Mark_No, mark_rev_no, DeleteFlag) VALUES

    ('C63-GPE105-499-003','1','10','10','1'),

    ('C63-GPE105-499-003','1','10','10','1'),

    ('C63-GPE105-499-004','1','10','10',NULL),

    ('C63-GPE105-499-004','1','10','40','1'),

    ('C63-GPE105-499-004','2','10','10',NULL),

    ('C63-GPE105-499-004','2','10','10',NULL),

    ('C63-GPE105-499-005','1','10','10',NULL),

    ('C63-GPE105-499-005','1','10','10',NULL),

    ('C63-GPE105-499-005','1','10','20','1'),

    ('C63-GPE105-499-005','1','10','10','1')

    CREATE CLUSTERED INDEX cx_LoadsOfStuff ON...

  • RE: Is possible create numbered sequences

    Peter Brinkhaus (8/6/2013)


    azdeji (8/6/2013)


    Both SQL codes work perfectly!

    Thanks Peter Brinkhaus and ChrisM@home

    Strange, because my solution gives an entirely different result then the solution of Chris

    Oh Peter, my humblest apology. I...

  • RE: Is possible create numbered sequences

    azdeji (8/6/2013)


    ...

    Up to 10000

    Is possible create numbered sequences like the ROW_ID above, where the row numbers repeat themselves up to 10000 into an empty column?

    In SQL server

    Thanks

    Yes it...

  • RE: Is possible create numbered sequences

    Peter Brinkhaus (8/6/2013)


    Something like this?

    ...

    Check out the last 20 rows of your result set, Peter.

  • RE: Is possible create numbered sequences

    WITH Tens AS (SELECT * FROM (VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0),(0)) d (n)),

    iTally AS (SELECT n = ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM Tens a CROSS JOIN Tens b CROSS JOIN Tens...

  • RE: need help with applying function within Query

    I reckon it's somewhere around your DOB, Lowell 😛

    SELECT *

    FROM (SELECT ticks = 624511296000000000) z

    CROSS APPLY (SELECT microseconds = z.ticks/100) a

    CROSS APPLY (SELECT milliseconds = a.microseconds/1000) b

    CROSS APPLY (SELECT...

Viewing 15 posts - 316 through 330 (of 1,229 total)