Forum Replies Created

Viewing 15 posts - 1,201 through 1,215 (of 2,458 total)

  • RE: Need help with a query that returns only rows that meet specific condition

    Scott did my first solution (that one only scans the table once)...

    Here's another way:

    SELECT UniqID

    FROM #SampleData

    WHERE Code = 'ABC'

    EXCEPT

    SELECT UniqID

    FROM #SampleData

    WHERE Code <> 'ABC'

    "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 count the instances of each word throughout comments field across the table?

    ignacio.jose (10/22/2015)


    Just finished reading http://www.sqlservercentral.com/articles/Tally+Table/72993/

    Impresive

    That article certainly helped me a great deal.

    "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 count the instances of each word throughout comments field across the table?

    ignacio.jose (10/21/2015)


    Sounds like you need to write a SQL script that will have a cursor that queries the table that has the column holding the string

    Then you will have 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 String Between Two Delimiters for Multiple Occurences SQL Server

    First welcome to SSC.

    My solution uses a hacked version of Jeff Moden's DelimitedSplit8K (the splitter mentioned in my signature). If you have not worked with a splitter before I...

    "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 count the instances of each word throughout comments field across the table?

    Using the splitter in my signature line you could do this:

    -- let's create some easily consumable DDL

    DECLARE @YourTable TABLE (RowNumber int primary key, Comments varchar(1000) NOT NULL);

    -- Insert sample values

    INSERT...

    "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: replace same more then one character in one column sql query

    mr.addikhan (10/20/2015)


    Alan.B (10/20/2015)


    mr.addikhan (10/20/2015)


    its not working 🙁 my tbl name is tblemp column name is empaddress

    I would suggest taking what I posted (or what Luis posted if order...

    "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: replace same more then one character in one column sql query

    mr.addikhan (10/20/2015)


    its not working 🙁 my tbl name is tblemp column name is empaddress

    I would suggest taking what I posted (or what Luis posted if order is important)...

    "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: replace same more then one character in one column sql query

    Luis Cazares (10/20/2015)


    Alan, your idea is good, but if order is important a tweak might be needed.

    CREATE FUNCTION dbo.RemoveDupes(@string varchar(8000))

    RETURNS TABLE AS

    RETURN

    WITH CTE AS(

    SELECT...

    "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: replace same more then one character in one column sql query

    using the splitter referenced in my signature line, you could create this function:

    CREATE FUNCTION dbo.RemoveDupes(@string varchar(8000))

    RETURNS TABLE AS RETURN

    SELECT NewString =

    (

    SELECT DISTINCT item+' '

    FROM DelimitedSplit8K(@string,' ')

    FOR XML PATH(''),...

    "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: Query to find distinct multiple instances of a pattern in a string

    Using Eirkur's sample data and the aforementioned splitter, you could do this:

    UPDATE dbo.TBL_SAMPLE_PARSE

    SET MyString = REPLACE(REPLACE(MyString,',',' '),'.',' ')

    SELECT DISTINCT Item

    FROM TBL_SAMPLE_PARSE

    CROSS APPLY dbo.delimitedSplit8K(MyString, ' ')

    WHERE item LIKE '%[##%##]%' ESCAPE '[';

    Edit:...

    "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 roll back all changes if not all statements executed successfully?

    Sean Lange (10/15/2015)


    nguyenanhminhxd (10/15/2015)


    I have a script contains multiple statements to update multiple tables. How can I make sure that either all statements get executed successfully or no changes apply...

    "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 roll back all changes if not all statements executed successfully?

    -- Create a table

    IF OBJECT_ID('tempdb..#X') IS NOT NULL DROP TABLE #X;

    CREATE TABLE #X (x int)

    -- start transaction

    BEGIN TRANSACTION

    INSERT #X SELECT 1

    INSERT #X SELECT 2

    INSERT...

    "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: What does Access do best?

    timwell (10/15/2015)


    Eric M Russell (10/15/2015)


    I believe Excel is more often used for professional data analysis than MS Access. What functionality is missing from Excel that she finds in MS Access?

    I...

    "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: Split values in the column

    You can also do this:

    SELECT

    J.DT_ID

    ,J.InvNo

    ,Salesmman = SUBSTRING(J.SalesCode,1,CHARINDEX('!',J.SalesCode)-1)

    ,Commision = SUBSTRING(J.Amount,1,CHARINDEX('!',J.Amount)-1)

    FROM @TEST_DATA J

    "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: Calculate Median value in SSRS

    Is calculating the median in the SQL Query that feeds the report an option?

    "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,201 through 1,215 (of 2,458 total)