Forum Replies Created

Viewing 15 posts - 1 through 15 (of 30 total)

  • RE: How to create a frequency report

    Hello again,

    I managed to find a simple solution that seems working on sample tables.

    ;WITH Final_TB AS

    (

    SELECT X.SAMPLE_ID, X.AntiBio, #TestTb1.P1, #TestTb1.P2, #TestTb1.P3, #TestTb1.P4 FROM

    (

    SELECT [Sample_ID],'AB1' AS [AntiBio]

    FROM #TestTb2 WHERE...

  • RE: Can I strictly limit access to database ?

    Dear Grant,

    Thanks for your help. I will check the login profiles and their privileges.

    Regards

  • RE: Can I strictly limit access to database ?

    AndrewSQLDBA (3/31/2013)


    You can put any of the user databases on the box into single user mode.

    Why would you be developing against a production database? If needed, create a database on...

  • RE: Combine multiple combinations to one

    Lynn Pettis (3/28/2013)


    Add on ORDER BY where you concatenate your values:

    IF object_id('tempdb..#testEnvironment') IS NOT NULL

    BEGIN

    DROP TABLE #testEnvironment;

    END;

    CREATE TABLE #testEnvironment ([Sample_ID] INT, [Rep_ID] INT, [Result] VARCHAR(20))

    INSERT INTO #testEnvironment

    SELECT 1, 1,...

  • RE: How to concatenate group of rows

    Cadavre (2/28/2013)


    So, to make sure I'm clear with what you want.

    With this sample data: -

    IF object_id('tempdb..#testEnvironment') IS NOT NULL

    BEGIN

    DROP TABLE #testEnvironment;

    END;

    SELECT [Sample_ID], [Rep_ID], [Result]

    INTO #testEnvironment

    FROM (VALUES(1, 1, 'O152'),(1, 2, 'O2'),(1,...

  • RE: Calculate percentage

    ryan.mcatee (3/23/2013)


    SELECT Antibiotic

    , SUM(CASE WHEN Result IN (1, 2) THEN 1 ELSE 0 END) AS Tests

    , SUM(CASE WHEN Result =...

  • RE: Counter inside SELECT

    Steven Willis (3/7/2013)


    Just to add another option with a slightly more complex query that doesn't require a seed value. Also, by adding identity columns it will keep the rows in...

  • RE: How to add item No. in SELECT

    Deque (3/7/2013)


    Does this do what you are looking for?

    SELECT C_NAME, ROW_NUMBER() OVER(PARTITION BY C_NAME ORDER BY C_NAME ASC) AS ITEM_NO, REQ_ITEM FROM @test1

    Yep, It worked.

    Thanks Deque

  • RE: Counter inside SELECT

    RZ52 (3/7/2013)


    Jason-299789 (3/7/2013)


    This should work especially if you're not bothered about the order of the insert for Table 1

    INSERT INTO @test1(C_NAME, C_CODE)

    (SELECT P_NAME,

    C_CODE = 'CL' +...

  • RE: Counter inside SELECT

    Jason-299789 (3/7/2013)


    This should work especially if you're not bothered about the order of the insert for Table 1

    INSERT INTO @test1(C_NAME, C_CODE)

    (SELECT P_NAME,

    C_CODE = 'CL' + CONVERT(VARCHAR(5),@x+ROW_NUMBER()...

  • RE: How to make a Pivote table

    Dear Lynn,

    Thanks for guidance. I read them and the articles gave me some idea. However, my main issue is how to...

  • RE: How to make a Pivote table

    Jeff Moden (3/1/2013)


    No answer in 14 hours. Take a look at the article at the first link in my signature below for a way to change that.

    Hi again,

    Following kind...

  • RE: How to make a Pivote table

    Dear Jeff,

    Thank for the link and guidance. I opened this topic about 2 hours ago. As here is midnight, I will come back tomorrow and modify my topic.

    Thanks again

  • RE: Custom order in SELECT

    Sean Lange (3/1/2013)


    Lowell, you would have to add a where clause to only return those rows that match. Notice below this will return a cartesian product.

    select *

    from

  • RE: Custom order in SELECT

    Erin Ramsay (3/1/2013)


    If your custom phrase is static you can use:

    select letter from @test1 order by (case letter when 'd' then 1 when 'c' then 2 when 'b'...

Viewing 15 posts - 1 through 15 (of 30 total)