Forum Replies Created

Viewing 15 posts - 2,311 through 2,325 (of 2,458 total)

  • RE: "USE DATABASE" in stored procedure

    Add USE statement to a proc (using DSQL):

    CREATE PROC xxx AS

    BEGIN

    DECLARE @sql varchar(100)='USE tempdb; SELECT * FROM sys.database_files;'

    EXEC(@sql);

    SET @sql='USE master; SELECT * FROM sys.database_files;'

    EXEC(@sql);

    END

    You can also accomplish this using 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: Question about Optional Parameters in Stored Procedures

    I can't speak to TVPs but I use this technique to create a default value in stored procedures and functions have seen it used quite often.

    I have always been...

    "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: Double Counting and Sign Reversals

    Great article Dwain! It also inspired me to read the N-Tuple article which I liked.

    It’s almost a shame (not really! J) that I no longer support Accounting applications because...

    "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: editing SQL Server 2008 query output file in linux

    NP. πŸ™‚

    "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: Divide N object to N person

    Edit: misread ddl. Said something stupid.

    I tried to solve this and failed. Well done Dwain C.

    "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: editing SQL Server 2008 query output file in linux

    There are some nuances I wont cover here but should work or at least get you started.

    To export a query from SQL Server to comma delimited CSV file

    1) Right-click...

    "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: DBCC Commands

    On the other side... I have never run REPAIR_ALLOW_DATA_LOSS.

    "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: Quert regarding getting the results based on months.

    This is not the most elegant or optimized approach but this will get you the result set that you are looking for...

    --Parameter

    DECLARE @topMonth int=3;

    --if a valid month is not...

    "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: ''=0 ?!?!

    dwain.c (12/17/2012)


    If you think those "typos" that pass SQL Server's parser seem weird, try this one:

    SELECT 7+$

    Thanks for the post dwain. That's really odd too; I would never think to...

    "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: Retrieve second of three values separated by spaces

    Another way:

    DECLARE @spitme TABLE (Item varchar(40));

    INSERT @spitme VALUES ('HEYE-B Euro-IPA 69793'), ('HEYE-B RFE-IPA 70940');

    SELECT SUBSTRING(Item, CHARINDEX(' ',Item)+1, LEN(Item)-(CHARINDEX(' ',Item)+CHARINDEX(' ',REVERSE(Item))))

    FROM @spitme

    Fun.

    "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: Retrieve second of three values separated by spaces

    Using Jeff Moden's splitter[/url] you can do this...

    DECLARE @spitme TABLE (Item varchar(40));

    INSERT @spitme VALUES ('HEYE-B Euro-IPA 69793'), ('HEYE-B RFE-IPA 70940');

    SELECT s.Item

    FROM @spitme val

    CROSS APPLY test.[dbo].[DelimitedSplit8K](val.Item,' ') s

    WHERE ItemNumber = 2

    "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: ''=0 ?!?!

    Thanks Gail.

    "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 all data where one condition is met

    Your typo messed me up too...

    You can also try:

    ;WITH x AS

    (SELECT ID, Stat, StatDate

    FROM #Apps

    WHERE Stat='AppRec' AND StatDate >= '2012-12-01' )

    SELECT ID, Stat, StatDate

    FROM #Apps

    WHERE ID...

    "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: IF statement with subquery problem

    zilla (12/17/2012)


    I have a sub query within my IF statement that evaluates to one single number that I am using for a comparison operator. I am thinking there is something...

    "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: Has SQL Query Termination (;) become mandatory in SQL Server 2012?

    In case anyone was curious - the line in the Ben Gan book I was referring to is:

    The SQL Server documentation indicates that not terminating T-SQL statements with a semicolon...

    "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 - 2,311 through 2,325 (of 2,458 total)