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'
Visual Basic Classic

Avatar of undefined
Last Comment
SStory
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
jsctechy
Flag of United States of America image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo