Forum Replies Created

Viewing 15 posts - 3,631 through 3,645 (of 3,957 total)

  • RE: String conversion

    Jeff Moden (5/9/2012)


    BWAAA-HAAA!!! This will do it! :-P:-D Makes a "great" interview question. :sick:

    WITH F(x) AS (SELECT TOP (CHECKSUM(66-ASCII('A'))) '/'+CONVERT(CHAR(8),GETDATE(),CAST(EXP(0) AS INT)) FROM sys.objects)

    SELECT STUFF(REPLACE(LEFT(x,POWER(73,1/2)*POWER(25,1/2.0)),'/0','/')

    ...

  • RE: remove specific row only if there is a duplicate row

    I have a rather strange alternative for you here. I say strange because the query plan looks ridiculously more complicated than either the one produced by Lynn's or by...

  • RE: Like query from another table

    If you don't want duplicates in ColdCoffee's suggestion:

    -- Replace:

    SELECT *

    -- With:

    SELECT DISTINCT Ac_no, Code_list

    Or, another alternative with a cheaper execution plan cost would be this (also eliminates duplicates):

    SELECT *

    FROM @Account...

  • RE: US Date Format in SQL Server

    The datetime datatype stores the data differently that the way you think it is being displayed. That's controlled by a SQL Server default setting.

    To "store" in US format as...

  • RE: Pivot Table Query

    ColdCoffee is right. You shouldn't burden your helpers with having to set up your DDL and sample data for you. Today I was feeling generous.

    Can do with PIVOT...

  • RE: US Date Format in SQL Server

    I guess if you want to run the query on SQL Server and you are content to return a character string to your MS Access application, you can do something...

  • RE: case statement

    Three other options are:

    SELECT CountofFailure = SUM(CAST(void AS INT))

    ,CountofSuccess = SUM(CAST(~void AS INT))

    FROM test

    SELECT CountofFailure = SUM(0 + void)

    ,CountofSuccess = SUM(1 - void)

    FROM test

    SELECT CountofFailure =...

  • RE: Summing distinct records

    Actually, I have a better idea. If you need to worry about ClientIDs that have accounts but no purchases (the above query won't work), use this.

    ;WITH CTE (ClientID, AccountNumber,...

  • RE: Summing distinct records

    I would do this with a correlated subquery, thusly:

    SELECT ClientID

    ,(SELECT COUNT(AccountNumber)

    FROM #ClientAccounts ca

    WHERE ca.ClientID = cp.ClientID

    GROUP BY ClientID) AS NumAccounts

    ,NumPurchases, AmtPurchases

    FROM (

    SELECT ClientID, COUNT(ClientID) AS NumPurchases,...

  • RE: Identify Bad Characters in a Table Column

    ChrisM@Work (5/8/2012)


    Interpreting the results from this isn't straightforward, at least not to me. I prefer the output formatted like this:

    SELECT Strings, x.Goodchars, y.Badchars

    FROM #t

    CROSS APPLY (

    SELECT SUBSTRING(Strings,n,1)

    FROM (SELECT TOP...

  • RE: Count Data in Large Seprated Text

    Is this the result you are looking for:

    DECLARE @l TABLE (ID INT, [Name] VARCHAR(30), Location VARCHAR(100))

    DECLARE @d CHAR(1)

    SET @d = ','-- Delimiter

    INSERT INTO @l (ID, [Name], Location)

    SELECT 1, 'Ronaldo', 'Country:Spain,...

  • RE: Help - I have not coded in a long time

    My humblest apologies sir!

    Seems I made several mistakes on this thread this day. Clearly the Force was not with me.

    Probably should stick to playing with my cats.

  • RE: Help - I have not coded in a long time

    Seemingly I have been challenged here.

    Rising to the occasion, I can take Jeff's wonderful articles on generating random data and concoct an approach of my own to generate random gaps....

  • RE: Generating Test Data: Part 2 - Generating Sequential and Random Dates

    Jeff Moden (4/30/2012)


    Samrat Bhatnagar (4/28/2012)


    These two part series were really useful. Thanks.

    Any suggestions on how to generate test data for following scenarios:

    1. Two tables linked using PK-FK relationship e.g. Product...

  • RE: Help - I have not coded in a long time

    Jeff Moden (4/30/2012)


    dwain.c (4/30/2012)


    Now this one ties with yours but my second solution comes up lowest.

    How did you measure?

    Actual execution plan costs.

    Before you say again that the actual execution plan...

Viewing 15 posts - 3,631 through 3,645 (of 3,957 total)