Link to home
Start Free TrialLog in
Avatar of jsctechy
jsctechyFlag for United States of America

asked on

Re-write SQL statement in VB. NET

hi there a have a sql query that i need to run it on my application, but when i add the quotations is giving me some errors. Here is the actual SQL statement can you experts help me figuring this out?

SELECT DISTINCT
CD_MAIN.NUMBER_KEY as PERMIT_NO, CT_MAIN.BUS_NAME as CONT_BUS,
ISNULL(CT_MAIN.CON_NAME, TAX_ROLL.NAME_LINE_1 + ' ' + TAX_ROLL.NAME_LINE_2 ) as LETTER_NAME, --OwnerTable.CON_NAME
ISNULL (CT_MAIN.ADDRESS, TAX_ROLL.ADDRESS_LINE_1) as LETTER_ADDRESS_1,
ISNULL (CT_MAIN.CITY + ' ' + CT_MAIN.STATE + ' ' + CT_MAIN.ZIP, TAX_ROLL.ADDRESS_LINE_2) as LETTER_ADDRESS_2

FROM      ((CD_MAIN
            INNER JOIN CD_ADDRESS ON CD_MAIN.NUMBER_KEY = CD_ADDRESS.NUMBER_KEY and CD_MAIN.TYPE_DEPT ='BUILDING'
            INNER JOIN CD_Parcel ON CD_MAIN.NUMBER_KEY = CD_PARCEL.NUMBER_KEY)
            LEFT OUTER JOIN CD_PEOPLE ContractorTable on CD_MAIN.NUMBER_KEY = ContractorTable.LINK_KEY and ContractorTable.RELATIONSHIP <>'OWNER')
            LEFT OUTER JOIN CT_MAIN ON ContractorTable.CON_KEY = CT_MAIN.ELEMENT_KEY
            LEFT OUTER JOIN CD_PEOPLE OwnerTable ON CD_MAIN.NUMBER_KEY = OwnerTable.LINK_KEY and OwnerTable.RELATIONSHIP ='OWNER'
            LEFT OUTER JOIN TAX_ROLL ON CD_Address.PARCEL_NO = TAX_ROLL.FOLIO_NUMBER

WHERE
      CD_MAIN.NUMBER_KEY = 'PermitNumber'
Avatar of SStory
SStory
Flag of United States of America image

1st Question:
    If this is SQL Server why wouldn't you just use a Stored Proc
2nd Question:
    Are you using a command object?  if not I would recommend it, for SQL injection prevention
3rd Question:
    Can we see some error messages? Code?

Avatar of jsctechy

ASKER

i was thinking on using a stored procedure but it needs a parameter and i don't know how to do it.

can you point me to the direction of how to do it?
ASKER CERTIFIED SOLUTION
Avatar of SStory
SStory
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial