Forum Replies Created

Viewing 15 posts - 1,591 through 1,605 (of 2,458 total)

  • RE: Find/Replace based on a table - strange results

    Okay, I can't come up with a pure set-based way to handle this but I have a solution that I think is pretty slick using a recursive CTE wrapped in...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Find/Replace based on a table - strange results

    I really like the way you think. Unfortunately UPDATE does not work the way you are trying to use it.

    Your DDL is bad and some sample data for questions...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: ROW_NUMBER/RANk RESET WHEN ON/OFF?

    Can you include ddl and sample data for #test

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: How to create numerous directories on a server using data from sql table

    Jeff Moden (4/16/2015)


    Alan.B (4/16/2015)


    What about a SQL Agent job that kicks off a script? Powershell perhaps?

    If that's not an option, and if Lowell's solution (enable xp_cmdshell then disable when...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: How to create numerous directories on a server using data from sql table

    What about a SQL Agent job that kicks off a script? Powershell perhaps?

    If that's not an option, and if Lowell's solution (enable xp_cmdshell then disable when you're done) does...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Add carriage return to a full address field

    spaghettidba (4/16/2015)


    In windows the line separator is CR+LF. In linux it's LF.

    CR = CHAR(13)

    LF = CHAR(10)

    Got it. Thanks!

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Add carriage return to a full address field

    spaghettidba (4/16/2015)


    Concat NULL yelds NULL:

    SELECT

    ISNULL(SAD.HOUSENUMBER + CHAR(13) + CHAR(10),'') +

    ISNULL(SAD.ADDRESS1 + CHAR(13) + CHAR(10),'') +

    ISNULL(SAD.ADDRESS2 +...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Unusual Recursive CTE with non-unique codes

    Good job with the DDL but to get a better answer it would be helpful if you could include some sample values so that we can better understand what you...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Clustered Index

    What do you mean by "Partition Column"?

    Partition get's used in many contexts: Partition key, Partitioned table... A partition key is generally a non-distinct value/key that is used to group...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Can Anyone give me a solution to my subquery in the from clause?

    Looks like you have duplicate column names in both tables but you are not using a table alias

    You query should look something like this:

    SELECT a.col1, a.col2, b.col1

    FROM a

    Join

    (

    <Subquery>

    ) AS...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Varchar(8000) Concat

    My observation is that an implicit conversion happens when you concatenate the two strings but it tops out at 8000.

    Declare @VariableA varchar(100);

    Declare @VariableB varchar(100);

    SET @VariableA = REPLICATE('x',100);

    SET...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: stored procedure text string replace

    You can get the schema, name and DDL for the stored procs from INFORMATION_SCHEMA.ROUTINES. Something like this...

    DECLARE @buildSprocsScript nvarchar(max) ='';

    SELECT @buildSprocsScript += 'DROP PROC '+specific_schema+'.'+specific_name+char(13)+'GO'+char(13)

    +REPLACE(ROUTINE_DEFINITION,'<what you want to replace>','<replace...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: SELECT COUNT(*) vs DMVs to get row count

    GilaMonster (4/13/2015)


    Alan.B (4/10/2015)


    Ok, quick update... I did some research on this - it appears that sys.partitions does not guarantee an accurate row count. According to Microsoft, the rows column in...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Looking for a training book recommendation for SQL 2012

    The book you listed is not a bad start at all. I actually own it but have not read it; as a DBA, however, I learned a ton from the...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: SELECT COUNT(*) vs DMVs to get row count

    Ok, quick update... I did some research on this - it appears that sys.partitions does not guarantee an accurate row count. According to Microsoft, the rows column in sys.partitions "Indicates...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

Viewing 15 posts - 1,591 through 1,605 (of 2,458 total)