Forum Replies Created

Viewing 15 posts - 2,281 through 2,295 (of 2,462 total)

  • RE: Single Update Query - Required

    This should get you started...

    IF OBJECT_ID('tempdb..#table1') IS NOT NULL

    DROP TABLE #table1;

    IF OBJECT_ID('tempdb..#table2') IS NOT NULL

    DROP TABLE #table2;

    CREATE TABLE #table1 (sno int unique NOT NULL, [sid] int NULL, sname varchar(2) unique...

    "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: Creating Stored Procedure

    dsrapid (3/11/2013)


    Hi,

    I have below table:

    ID URL

    1 https://google.com

    2 https://facebook.com

    3 https://yahoo.com

    4 https://gmail.com

    I am trying to create a procedure where I take the input...

    "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: Combine variable and select statement

    Its worth noting that, if you do not assign a value to @EndUserDel it will return NULL value. See my comments in the code below

    IF OBJECT_ID('tempdb..#service') IS NOT NULL

    DROP TABLE...

    "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: looping thru views

    rummings (3/11/2013)


    Alan,

    Thank you for the code.... it worked great!

    Charlie

    Any time.

    "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: looping thru views

    Cursors, loops and dSQL fall under the last choice column but this is one of those cases...

    For tables you would do this:

    EXEC sp_MSforeachtable'SELECT TOP 1 * FROM ?'

    For...

    "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: Hierarchies in SQL

    I know I am a little late here but, Great article Gus.

    FYI - the to Celko's article (http://www.intelligententerprise.com/001020/celko.jhtml.) is broke 😉

    "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: UDF Help

    Lynn, Jeff, Kevin, ChrisM: thank you very much. This has been a particularly informative and excellent thread. It's given me a lot of new things to chew on.

    Inline Table...

    "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: UDF Help

    This is something I need to play around with more. I took what Jeff said to imply that, in the code below, the iTVF function (nsq_iTVF) would be faster than...

    "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: Compare list of tables in two Databases from SSMS

    syedathariqbal (3/1/2013)


    Managed to get the list using below query.

    SELECT TABLE_NAME FROM [DB1].information_schema.TABLES

    Where TABLE_TYPE='BASE TABLE'

    EXCEPT

    SELECT TABLE_NAME FROM [DB2].information_schema.TABLES

    Where TABLE_TYPE='BASE TABLE'

    In case there are other schemas:

    SELECT TABLE_SCHEMA, TABLE_NAME...

    "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: Generate reports

    Google sp_send_dbmail.

    "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: Updating specific rows

    No problem Amy.

    That's actually a newer technique for me too and has been very helpful. You can do deletes in the same way...

    ;WITH X AS (SELECT * FROM dbo.emp...

    "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: UDF Help

    Jeff Moden (2/25/2013)


    Alan.B (2/25/2013)


    If i am understand right. Function can return only one value. am i right?

    Scalar functions return one value, table valued functions return a table variable.

    Inline Table...

    "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: UDF Help

    If i am understand right. Function can return only one value. am i right?

    Scalar functions return one value, table valued functions return a table variable.

    "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: Updating specific rows

    Amy.G (2/25/2013)


    ...Now, I know if I just want a result set, I can use the query...

    If you can produce the result set then all you can can produce an update...

    "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: LIKE Operator OR Regular Expressions?

    SQLWannabe (2/25/2013)


    Alan,

    Thanks for the resposne. I should have been more clear. What I should've said was:

    "I need to change the collation in my query".

    The COLLATE function/keyword is definitely...

    "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,281 through 2,295 (of 2,462 total)