Performance Issue

  • I believe the issue is with the API, but have been asked to test performance for the SP below.

    You pass the propertyID to the proc and it will return the propertydetails.

    Nothing stands out to me... Anyone see anything I'm missing?

     

    Thanks in advance

    Susan

     

    Here is the SP in question with the schema below

    SET

    ANSI_NULLS ON

    GO

    SET

    QUOTED_IDENTIFIER ON

    GO

    ALTER

    PROCEDURE [dbo].[usp_HomeDetailsPropertyID_OffercountyAUTAUGA]

    @PropertyID

    VARCHAR(100)

    AS

    BEGIN

    SET NOCOUNT ON;

    SELECT DISTINCT

    SA_PROPERTY_ID

    AS PropertyID,

    SA_SITE_HOUSE_NBR

    AS PropertyAddressHouseNbr,

    SA_SITE_STREET_NAME

    AS PropertyAddressStreetName,

    SA_SITE_SUF

    AS PropertyAddressSuffix,

    SA_SITE_UNIT_PRE

    AS PropertyAddressUnitPrefix,

    SA_SITE_UNIT_VAL

    AS PropertyAddressUnitValue,

    CASE

    WHEN ISNULL(SA_SITE_CITY, '') = '' THEN ''

    ELSE LTRIM(RTRIM(SA_SITE_CITY))

    END AS PropertyAddressCity,

    CASE

    WHEN ISNULL(SA_SITE_STATE,'') = '' THEN ''

    ELSE LTRIM(RTRIM(SA_SITE_STATE))

    END AS PropertyAddressState,

    SA_SITE_ZIP

    AS PropertyAddressZip,

    ISNULL(SA_NBR_BEDRMS, 0) AS NBR_BEDRMS,

    ISNULL(SA_NBR_BATH, 0) AS NBR_BATH,

    ISNULL(SA_NBR_RMS, 0) AS NBR_RMS,

    ISNULL(SA_NBR_Stories, 0) AS NBR_Stories,

    ISNULL(SA_SQFT, 0) AS SQFT_ASSR_TOT,

    ISNULL(SA_SQFT_DQ, 0) AS SQFT_Derived,

    ISNULL(SA_YR_BLT, 2000) AS YearBuilt,

    latitude

    ,

    longitude

    ,

    SR_SITE_ADDR_RAW

    AS PropertyAddressRaw,

    ISNULL(USE_CODE_STD, '') AS ConstructionQuality,

    SA_SITE_STREET_NAME

    AS county,

    ISNULL(SA_BSMT_FIN_SQFT, 0) AS FinishedSQFT1,

    ISNULL(SA_BSMT_FIN_SQFT, 0) AS FinishedSQFT2,

    ISNULL(MM_ASSESSMENT_YEAR, 0) AS YR_land_Appraise,

    ISNULL(SA_GRG_SQFT_1, 0) AS grg_SQFT_1,

    SA_PARCEL_NBR_PRIMARY

    AS APN,

    ISNULL(SA_LOTSIZE, 0) AS lotsize,

    ReplyAVM

    AS REPLY_VALUATION,

    ReplyScore

    AS REPLY_CONFIDENCE,

    SA_DATE_TRANSFER

    ,

    SA_VAL_TRANSFER

    FROM

    countyAUTAUGA

    (NOLOCK)

    WHERE

    SA_PROPERTY_ID

    IN (' + @PropertyID + ')

    AND SA_PROPERTY_ID IS NOT NULL

    ORDER BY

    SA_DATE_TRANSFER

    END

    GO

    SET

    ANSI_NULLS OFF

    GO

    SET

    QUOTED_IDENTIFIER OFF

    GO

     

    Schema begins

     

    SET

    ANSI_NULLS ON

    GO

    SET

    QUOTED_IDENTIFIER ON

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND type in (N'U'))

    BEGIN

    CREATE

    TABLE [dbo].[countyAUTAUGA](

    [SA_PROPERTY_ID] [int]

    NOT NULL,

    [mm_FIPS_STATE_CODE] [tinyint]

    NOT NULL,

    [mm_FIPS_MUNI_CODE] [smallint]

    NOT NULL,

    [MM_MUNI_CODE] [char]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

    [SA_PARCEL_NBR_PRIMARY] [varchar]

    (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1] [varchar]

    (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1_ET_FLAG] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1_FIRST] [varchar]

    (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1_GROUP] [varchar]

    (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1_LAST] [varchar]

    (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1_MID] [varchar]

    (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1_PRE] [varchar]

    (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1_SP_FIRST] [varchar]

    (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1_SP_MID] [varchar]

    (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1_SP_SUF] [varchar]

    (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_1_SUF] [varchar]

    (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_2] [varchar]

    (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_2_FIRST] [varchar]

    (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_2_LAST] [varchar]

    (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_2_MID] [varchar]

    (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_2_SP_FIRST] [varchar]

    (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_2_SP_MID] [varchar]

    (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNER_2_SUF] [varchar]

    (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_OWNERSHIP_STATUS_CODE] [char]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_HOUSE_NBR] [varchar]

    (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_FRACTION] [varchar]

    (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_DIR] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_STREET_NAME] [varchar]

    (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_SUF] [varchar]

    (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_POST_DIR] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_UNIT_PRE] [varchar]

    (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_UNIT_VAL] [varchar]

    (6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_CITY_STATE] [varchar]

    (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_ZIP] [int]

    NULL,

    [SA_SITE_City] [varchar]

    (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_State] [char]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_CRRT] [varchar]

    (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_SITE_PLUS_4] [smallint]

    NULL,

    [SR_SITE_ADDR_RAW] [varchar]

    (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_HOUSE_NBR] [varchar]

    (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_FRACTION] [varchar]

    (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_DIR] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_STREET_NAME] [varchar]

    (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_SUF] [varchar]

    (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_POST_DIR] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_UNIT_PRE] [varchar]

    (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_UNIT_VAL] [varchar]

    (6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_CITY_STATE] [varchar]

    (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_STATE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_MAIL_ZIP] [int]

    NULL,

    [SA_SITE_MAIL_SAME] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_LGL_DSCRPTN] [varchar]

    (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_TOWNSHIP] [varchar]

    (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_PHONE_NBR] [varchar]

    (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_PRIVACY_CODE] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [USE_CODE_MUNI] [varchar]

    (6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [USE_CODE_STD] [varchar]

    (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_ZONING] [varchar]

    (13) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [MM_ASSESSMENT_YEAR] [smallint]

    NULL,

    [SA_VAL_ASSD] [int]

    NULL,

    [SA_VAL_ASSD_IMPRV] [int]

    NULL,

    [SA_VAL_ASSD_LAND] [int]

    NULL,

    [SA_IMPRV_PCT] [int]

    NULL,

    [SA_TAX_VAL] [numeric]

    (9, 2) NULL,

    [SA_TAX_YEAR_DELINQ] [smallint]

    NULL,

    [SA_VAL_FULL_CASH] [int]

    NULL,

    [SA_VAL_CURRENT_LIMIT] [int]

    NULL,

    [SA_VAL_MARKET] [int]

    NULL,

    [SA_APPRAISE_VAL] [int]

    NULL,

    [SA_YR_BLT] [smallint]

    NULL,

    [SA_YR_BLT_EFFECT] [smallint]

    NULL,

    [SA_BLDG_SHAPE_CODE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_ARCHITECTURE_CODE] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_STRUCTURE_CODE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_EXTERIOR_1_CODE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_EXTERIOR_2_CODE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_CONSTRUCTION_CODE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_CONSTRUCTION_QLTY] [numeric]

    (3, 1) NULL,

    [SA_LOT_DEPTH] [smallint]

    NULL,

    [SA_LOT_WIDTH] [smallint]

    NULL,

    [SA_LOTSIZE] [numeric]

    (14, 4) NULL,

    [SA_SQFT] [int]

    NULL,

    [SA_SQFT_DQ] [int]

    NULL,

    [SA_ADDTNS_SQFT] [smallint]

    NULL,

    [SA_ATTIC_SQFT] [smallint]

    NULL,

    [SA_BSMT_FIN_SQFT] [smallint]

    NULL,

    [SA_GRG_SQFT_1] [smallint]

    NULL,

    [SA_HEATING_COOLING] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_HEATING_DETAIL] [tinyint]

    NULL,

    [SA_COOLING_DETAIL] [tinyint]

    NULL,

    [SA_FIREPLACE_CODE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_GARAGE_CARPORT] [varchar]

    (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_NBR_BATH] [numeric]

    (5, 2) NULL,

    [SA_NBR_BEDRMS] [smallint]

    NULL,

    [SA_NBR_RMS] [smallint]

    NULL,

    [SA_NBR_STORIES] [tinyint]

    NULL,

    [SA_NBR_UNITS] [smallint]

    NULL,

    [SA_POOL_CODE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_ROOF_CODE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_VIEW_CODE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_DATE_TRANSFER] [int]

    NULL,

    [SA_VAL_TRANSFER] [int]

    NULL,

    [SR_BUYER] [varchar]

    (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SR_SELLER] [varchar]

    (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SR_ARMS_LENGTH_FLAG] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SR_TRAN_TYPE] [varchar]

    (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SR_FULL_PART_CODE] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SR_MULT_APN_FLAG_KEYED] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SR_MULT_PORT_CODE] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_DATE_NOVAL_TRANSFER] [int]

    NULL,

    [AsARMS_LENGTH_FLAG_DFS] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_LOAN_VAL_1] [int]

    NULL,

    [SR_LOAN_VAL_2] [int]

    NULL,

    [SR_LOAN_VAL_3] [int]

    NULL,

    [HEDONIC_VALUE] [int]

    NULL,

    [ASSESSED_VALUE] [int]

    NULL,

    [RSI_VALUE] [int]

    NULL,

    [APPR_EMUL_VALUE] [int]

    NULL,

    [AVM_VALUE] [int]

    NULL,

    [ReplyAVM] [int]

    NULL,

    [ReplyScore] [int]

    NULL,

    [Alpha_Reliability_Score] [char]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [RELIABILITY_SCORE] [int]

    NULL,

    [SA_X_COORD] [float]

    NULL,

    [SA_Y_COORD] [float]

    NULL,

    [Longitude] [float]

    NULL,

    [Latitude] [float]

    NULL,

    [SA_CENSUS_TRACT] [varchar]

    (7) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_CENSUS_BLOCK_GROUP] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [SA_GEO_QLTY_CODE] [varchar]

    (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    [STREET_NAME_SOUNDEX] [char]

    (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

    )

    ON [PRIMARY]

    END

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'idx_sa_property_id')

    CREATE

    CLUSTERED INDEX [idx_sa_property_id] ON [dbo].[countyAUTAUGA]

    (

    [SA_PROPERTY_ID]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'dbo.idx_AddrRaw')

    CREATE

    NONCLUSTERED INDEX [dbo.idx_AddrRaw] ON [dbo].[countyAUTAUGA]

    (

    [SR_SITE_ADDR_RAW]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'dbo.idx_HomeComp')

    CREATE

    NONCLUSTERED INDEX [dbo.idx_HomeComp] ON [dbo].[countyAUTAUGA]

    (

    [SA_NBR_BATH]

    ASC,

    [SA_NBR_BEDRMS]

    ASC,

    [SA_LOTSIZE]

    ASC,

    [SA_SQFT]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'dbo.idx_Zip')

    CREATE

    NONCLUSTERED INDEX [dbo.idx_Zip] ON [dbo].[countyAUTAUGA]

    (

    [SA_SITE_ZIP]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'idx_City')

    CREATE

    NONCLUSTERED INDEX [idx_City] ON [dbo].[countyAUTAUGA]

    (

    [SA_SITE_City]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'idx_CordX')

    CREATE

    NONCLUSTERED INDEX [idx_CordX] ON [dbo].[countyAUTAUGA]

    (

    [SA_X_COORD]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'idx_CordY')

    CREATE

    NONCLUSTERED INDEX [idx_CordY] ON [dbo].[countyAUTAUGA]

    (

    [SA_Y_COORD]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'idx_DateTrans')

    CREATE

    NONCLUSTERED INDEX [idx_DateTrans] ON [dbo].[countyAUTAUGA]

    (

    [SA_DATE_TRANSFER]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'idx_Latitude')

    CREATE

    NONCLUSTERED INDEX [idx_Latitude] ON [dbo].[countyAUTAUGA]

    (

    [Latitude]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'idx_Longitude')

    CREATE

    NONCLUSTERED INDEX [idx_Longitude] ON [dbo].[countyAUTAUGA]

    (

    [Longitude]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'idx_ReplyAvm')

    CREATE

    NONCLUSTERED INDEX [idx_ReplyAvm] ON [dbo].[countyAUTAUGA]

    (

    [ReplyAVM]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'idx_State')

    CREATE

    NONCLUSTERED INDEX [idx_State] ON [dbo].[countyAUTAUGA]

    (

    [SA_SITE_State]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    GO

    IF

    NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[countyAUTAUGA]') AND name = N'idx_ValTrans')

    CREATE

    NONCLUSTERED INDEX [idx_ValTrans] ON [dbo].[countyAUTAUGA]

    (

    [SA_VAL_TRANSFER]

    ASC

    )

    WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

  • You don't say what performance problem you are having, so I'll take a stab at this...

    You are trying to accomplish two things with the SELECT statement.

    1. Get DISTINCT rows.

    2. Manipulate some of the data (CASE statements).

    I think it is the combination of the two that is causing the problem. It has to manipulate all the data and then determine which rows are DISTINCT.

    Possible solution:

    I would try a nested SELECT. The inner (nested) SELECT should pull back the DISTINCT rows. The outer SELECT should then manipulate the data being returned.

    Also, what is the point of this WHERE clause:

    SA_PROPERTY_ID IN (' + @PropertyID + ')

    AND SA_PROPERTY_ID IS NOT NULL

    If you are only getting rows where SA_PROPERTY_ID is in a specific list, then SA_PROPERTY_ID CANNOT be NULL. That makes the second part of the WHERE unnecessary. In other words, if you have this:

    WHERE SA_PROPERTY_ID IN ('1','2','3')

    AND SA_PROPERTY_ID IS NOT NULL

    It will only pull rows with SA_PROPERTY_ID of 1 and/or 2 and/or 3. NULL will never be returned, so why have that line?

    -SQLBill

  • If you can only send in one property id at a time, why do

    WHERE

    SA_PROPERTY_ID

    IN (' + @PropertyID + ')

    AND SA_PROPERTY_ID IS NOT NULL

    instead of

    WHERE

    SA_PROPERTY_ID = 

    @PropertyID

    and I'd declare the variable as an INT or convert the varchar to an INT to be used in the query after making sure it was indeed numeric and not null.


    And then again, I might be wrong ...
    David Webb

  • And..(1) You are using functions on column names

    (2) You are using DISTINCT , ORDER BY which use tempdb. So if you have multiple calls to the proc your tempdb could be the bottleneck.

    ******************
    Dinakar Nethi
    Life is short. Enjoy it.
    ******************

  • Thanks for your help!!

Viewing 5 posts - 1 through 4 (of 4 total)

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