Passing Parameter with a wildcard

  • Background:I am running queries against pre-2005 databases.

    I'm trying to normalize data from a table (ID, Value1, Value2, Value3...Value12 where Value contains each sequence of a diagnosis instead of having ID, Sequence, Diagnosis)

    For reporting, I need to normalize, but can't use unpivot, and have already done the 12 iterations of unioning the data together.

    The problem: The ID has a length of 14, but when a user would be passing a parameter in, they only need to enter in the first 12 because the last two are always either 00 or 01.

    When I run the query with the criteria ID LIKE @Parameter + '%' in Reporting Services it takes ages to run.

    I've also tried left(ID, 12) = @Parameter, which takes just as long.

    However, when I pass a literal value in i.e. ID LIKE 123456789123 + '%' it takes less than a second.

    I don't know if there is something I can do better to get that parameter in and return everything for the first 12 of that ID, so any ideas or suggestions would be VERY much appreciated!

  • Hi and welcome to SSC. In order to help you need to provide some information. Please see the first link in my signature for best practices when asking questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • I'm confused. I did provide information. I'm not sure what else you need for my specific issue?

    The part that I'm having issues with is passing a parameter with a wildcard...it's working, but it is slow.

    I've tried a few other things as well (see the original post), but they are just as slow.

  • Well it is tough to help with performance problems without some details. Things like what does the table look like? What is the desired output? What does the query you are running look like? Indexes on the tables? Are the statistics updated on the tables etc.

    Here is a link that does a great job explaining the types of things needed to help with performance problems. It does take some effort on your part but otherwise we are just shooting blind.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (5/10/2012)


    Things like what does the table look like?

    Like I said, it's de-normalized. It has fields like ID, Value1, Value2, Value3...Value12, where Value should be in its own column instead of split out 12 different times.

    Sean Lange (5/10/2012)


    What is the desired output?

    Again, like I said, a normalized data set that I can pass a user defined parameter to.

    Sean Lange (5/10/2012)


    What does the query you are running look like?

    Like I said, it's unioning the table to itself 12 times in order to normalize it.

    Sean Lange (5/10/2012)


    Indexes on the tables? Are the statistics updated on the tables etc.

    This I didn't include. It's indexed on the ID.

    Sean Lange (5/10/2012)


    Are the statistics updated on the tables

    I'm not sure. I don't have permissions to do anything besides read/select from the table.

    SELECT LEFT(SUBNO, 12), Diagnosis, FHDXDESC, PROV_NAME, DOS, 1 AS Frequency

    FROM (SELECT subno, diagnosis, source, prov_name, m.claim_ref_num, CONVERT(datetime, Beg_Date_of_Serv) AS DOS

    FROM (SELECT Sub_ID AS SUBNO, PRIMARY_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Second_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Tertiary_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_4TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_5TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_6TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)) m LEFT JOIN

    dbo.meddet_new_format md(nolock) ON md.claim_ref_num = m.claim_ref_num

    UNION

    SELECT subno, diagnosis, source, prov_name, h.claim_ref_num, CONVERT(datetime, beg_date_serv) AS DOS

    FROM (SELECT Sub_ID AS SUBNO, Primary_Diag_Icd AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Second_Diag_Icd AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, tertiary_Diag_Icd AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Diag_4th AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Diag_5th AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Diag_6th AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)) h LEFT JOIN

    dbo.hospdet_new_format hd(nolock) ON h.Claim_Ref_Num = hd.claim_ref_num) c LEFT JOIN

    IEHPSQL2.DIam_725.diamond.JDIAGNM0_Dat d ON d .FHDXCODE = diagnosis

    GROUP BY SUbno, Prov_Name, Diagnosis, fhdxdesc, dos

    HAVING (subno = @subscriber + '00' OR

    subno = @subscriber + '01')

    --I've also tried subno LIKE @subscriber +'%' and left(subno,12) = @subscriber

    AND diagnosis IS NOT NULL AND diagnosis <> '999.99' AND diagnosis <> 'DXINV' AND diagnosis <> ''

  • Do you have an index on the ID field? I presume you would....

    This might be a situation where it would be worth creating a computed column that contained only the first 12 characters of your ID (call it ID12?), then creating an index on that computed column.

    You could then bypass the inefficiency of the LIKE statement and query directly on the first 12 characters only:

    SELECT ID, Value1... -- etc...

    FROM MyTable

    where ID12 = @Parameter -- where @Parameter contains the first 12 characters of the ID

    Rob Schripsema
    Propack, Inc.

  • Sorry -- hadn't read your entire post. Looks like you don't have permissions to modify the table/indexes at all. That would rule out implementing my suggestion....

    Rob Schripsema
    Propack, Inc.

  • Yes, which is unfortunate. And it makes absolutely no sense, because the other set of claims tables are set up with just the 12 of the ID and indexed as such as well. I don't understand why they wouldn't do it with these tables as well. Frustrating.:sick:

  • Is this a direct query or are you using a stored procedure? Can you modify the stored procedure if that is what you are using?

  • themangoagent (5/10/2012)


    Sean Lange (5/10/2012)


    Things like what does the table look like?

    Like I said, it's de-normalized. It has fields like ID, Value1, Value2, Value3...Value12, where Value should be in its own column instead of split out 12 different times.

    Sean Lange (5/10/2012)


    What is the desired output?

    Again, like I said, a normalized data set that I can pass a user defined parameter to.

    Sean Lange (5/10/2012)


    What does the query you are running look like?

    Like I said, it's unioning the table to itself 12 times in order to normalize it.

    Sean Lange (5/10/2012)


    Indexes on the tables? Are the statistics updated on the tables etc.

    This I didn't include. It's indexed on the ID.

    Sean Lange (5/10/2012)


    Are the statistics updated on the tables

    I'm not sure. I don't have permissions to do anything besides read/select from the table.

    SELECT LEFT(SUBNO, 12), Diagnosis, FHDXDESC, PROV_NAME, DOS, 1 AS Frequency

    FROM (SELECT subno, diagnosis, source, prov_name, m.claim_ref_num, CONVERT(datetime, Beg_Date_of_Serv) AS DOS

    FROM (SELECT Sub_ID AS SUBNO, PRIMARY_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Second_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Tertiary_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_4TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_5TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_6TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)) m LEFT JOIN

    dbo.meddet_new_format md(nolock) ON md.claim_ref_num = m.claim_ref_num

    UNION

    SELECT subno, diagnosis, source, prov_name, h.claim_ref_num, CONVERT(datetime, beg_date_serv) AS DOS

    FROM (SELECT Sub_ID AS SUBNO, Primary_Diag_Icd AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Second_Diag_Icd AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, tertiary_Diag_Icd AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Diag_4th AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Diag_5th AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Diag_6th AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)) h LEFT JOIN

    dbo.hospdet_new_format hd(nolock) ON h.Claim_Ref_Num = hd.claim_ref_num) c LEFT JOIN

    IEHPSQL2.DIam_725.diamond.JDIAGNM0_Dat d ON d .FHDXCODE = diagnosis

    GROUP BY SUbno, Prov_Name, Diagnosis, fhdxdesc, dos

    HAVING (subno = @subscriber + '00' OR

    subno = @subscriber + '01')

    --I've also tried subno LIKE @subscriber +'%' and left(subno,12) = @subscriber

    AND diagnosis IS NOT NULL AND diagnosis <> '999.99' AND diagnosis <> 'DXINV' AND diagnosis <> ''

    The point of my asking these kinds of details is not to irritate you. It is so I can get an idea of what you are trying to do. Just saying a table is unioned 12 times doesn't provide much detail. Especially with performance problems the more details the better. Without knowing the table structure and the query you can't even begin to help with performance problems. Maybe you had a bunch of scalar UDFs in your query. Had that been the case we would take an entirely different approach.

    From reading your query it looks like you could possibly benefit from indexes on subno and/or diagnosis.

    As a side topic, why all the nolock hints?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • It's a direct query. I'm using it to create a report in SQL Server Reporting Services that will be posted to a report server.

    I've tried one more thing (which is also slow), and that was to set the ID to select from this:

    Having

    subno in (Select SubscriberIDLong

    from

    (select @SUBNO + '00' as SubscriberIDLong

    union all

    Select @SUBNO + '01'as SubscriberIDLong

    )c)

    and

    diagnosis is not null and diagnosis <> '999.99' and diagnosis <> 'DXINV' and diagnosis <> ''

  • This problem is almost certainly due to parameter sniffing. Gail has a good article on Parameter Sniffing[/url]

    There are other issues with your code, though. You should use a WHERE clause instead of the HAVING clause that you currently have. You should use a DISTINCT clause intsead of the GROUP BY clause that you currently have, although even that indicates a potential problem with your data. You're scanning the table more times than is necessary. You should use a CROSS APPLY for your normalization. For example, this code:

    SELECT subno, diagnosis, source, prov_name, m.claim_ref_num, CONVERT(datetime, Beg_Date_of_Serv) AS DOS

    FROM (

    SELECT Sub_ID AS SUBNO, PRIMARY_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Second_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Tertiary_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_4TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_5TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_6TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    ) m

    can be rewritten as

    SELECT m.Sub_ID AS SubNo, d.Diagnosis, m.Prov_Name, m.Claim_Ref_Num, CONVERT(DATETIME, m.Beg_Date_of_Serv) AS DOS

    FROM dbo.Medhdr_New_Format AS m

    CROSS APPLY (

    SELECT m.Primary_Diag_ICD

    UNION

    SELECT m.Second_Diag_ICD

    UNION

    SELECT m.Tertiary_Diag_ICD

    UNION

    SELECT m.Diag_4th

    UNION

    SELECT m.Diag_5th

    UNION

    SELECT m.Diag_6th

    ) AS d(Diagnosis)

    Instead of reading the medhdr_new_format table six times, it only needs to read it once.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • I didn't think you were trying to irritate me, Sean. To be faire, I did initially include most of the details you requested. I know that it's not easy to help with minimal data, but my problem isn't with the data (aside from it not being normalized, more's the pity). The data will pull quick as lightening with directly stated criteria.

    The nolocks are because that's what I've been asked to do when running queries against these tables. Is there a better way?

  • themangoagent (5/10/2012)


    I didn't think you were trying to irritate me, Sean. To be faire, I did initially include most of the details you requested. I know that it's not easy to help with minimal data, but my problem isn't with the data (aside from it not being normalized, more's the pity). The data will pull quick as lightening with directly stated criteria.

    The nolocks are because that's what I've been asked to do when running queries against these tables. Is there a better way?

    At the very least the query itself has helped immensely with some considerations. Sometimes adding a parameter to query that is not optimal can be the turning point into super slowness. It looks like this is possibly the case here. I am interested to see how this changes if you try Drew's suggestion above. Although you did indicate this is not a stored proc so sniffing is not likely part of the equation here.

    As for the nolocks I am curious the reasoning you were told. Often we hear things like "it makes it go faster". Sadly it isn't a "go fast" feature. Here are a couple a good article discussing this hint.

    http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx

    http://sqlblog.com/blogs/andrew_kelly/archive/2009/04/10/how-dirty-are-your-reads.aspx

    Now I am not saying that you should immediately go change everything. I am merely suggesting that this hint tends to be overused. It does have it's place although pretty rare. From your comment about being told to add that hint when querying these tables suggest you are probably not getting the best advice.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • themangoagent (5/10/2012)


    Sean Lange (5/10/2012)


    Things like what does the table look like?

    Like I said, it's de-normalized. It has fields like ID, Value1, Value2, Value3...Value12, where Value should be in its own column instead of split out 12 different times.

    Sean Lange (5/10/2012)


    What is the desired output?

    Again, like I said, a normalized data set that I can pass a user defined parameter to.

    Sean Lange (5/10/2012)


    What does the query you are running look like?

    Like I said, it's unioning the table to itself 12 times in order to normalize it.

    Sean Lange (5/10/2012)


    Indexes on the tables? Are the statistics updated on the tables etc.

    This I didn't include. It's indexed on the ID.

    Sean Lange (5/10/2012)


    Are the statistics updated on the tables

    I'm not sure. I don't have permissions to do anything besides read/select from the table.

    SELECT LEFT(SUBNO, 12), Diagnosis, FHDXDESC, PROV_NAME, DOS, 1 AS Frequency

    FROM (SELECT subno, diagnosis, source, prov_name, m.claim_ref_num, CONVERT(datetime, Beg_Date_of_Serv) AS DOS

    FROM (SELECT Sub_ID AS SUBNO, PRIMARY_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Second_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Tertiary_DIAG_ICD AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_4TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_5TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, DIAG_6TH AS Diagnosis, 'Medical' AS Source, PROV_NAME, Claim_ref_num

    FROM dbo.medhdr_new_format(nolock)) m LEFT JOIN

    dbo.meddet_new_format md(nolock) ON md.claim_ref_num = m.claim_ref_num

    UNION

    SELECT subno, diagnosis, source, prov_name, h.claim_ref_num, CONVERT(datetime, beg_date_serv) AS DOS

    FROM (SELECT Sub_ID AS SUBNO, Primary_Diag_Icd AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Second_Diag_Icd AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, tertiary_Diag_Icd AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Diag_4th AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Diag_5th AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)

    UNION

    SELECT Sub_ID AS SUBNO, Diag_6th AS Diagnosis, 'Hospital' AS Source, Prov_Name, Claim_ref_num

    FROM dbo.hosphdr_new_format(nolock)) h LEFT JOIN

    dbo.hospdet_new_format hd(nolock) ON h.Claim_Ref_Num = hd.claim_ref_num) c LEFT JOIN

    IEHPSQL2.DIam_725.diamond.JDIAGNM0_Dat d ON d .FHDXCODE = diagnosis

    GROUP BY SUbno, Prov_Name, Diagnosis, fhdxdesc, dos

    HAVING (subno = @subscriber + '00' OR

    subno = @subscriber + '01')

    --I've also tried subno LIKE @subscriber +'%' and left(subno,12) = @subscriber

    AND diagnosis IS NOT NULL AND diagnosis <> '999.99' AND diagnosis <> 'DXINV' AND diagnosis <> ''

    I have an idea but I need you to do a couple of things for me.

    One, can you modify the code above so that it is obvious from the code which tables the columns belong (use the table aliases on the columns).

    Two, can you at least tell us what the data types of the columns are.

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

You must be logged in to reply to this topic. Login to reply