Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

sql parameterized query question mark placement with single quote in code

Hello All;

In the following statement, I need to know how to place the ? for the parameterized Query.
The part we are looking at is
 (CHARINDEX('/?/', '/' + Tracks.LID) > 0)
When run in SSMS, this is the way it will look
 (CHARINDEX('/1/', '/' + Tracks.LID) > 0)
(Replacing the ? with a number)

sqlctLabel.commandtext="SELECT COUNT(DISTINCT Tracks.AlbumID) AS Albums FROM Tracks INNER JOIN Albums ON Tracks.AlbumID = Albums.AlbumID INNER JOIN Artists ON Albums.ArtistID = Artists.ArtistID WHERE (CHARINDEX('/?/', '/' + Tracks.LID) > 0) GROUP BY Artists.ArtistName, Artists.ArtistID"
sqlctLabel.Parameters.Append sqlctLabel.CreateParameter("@LID", adInteger, adParamInput, , strLabelID)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany 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
Avatar of Wayne Barron

ASKER

Received the following error.


Microsoft OLE DB Provider for SQL Server error '80040e14'
Argument data type int is invalid for argument 1 of charindex function.

As for the @LID
I tried it using your code, and I get this.


Microsoft OLE DB Provider for SQL Server error '80040e14'
Must declare the scalar variable "@LID".
Got it.
Had to change my code around a little from
adInteger
To
adVarChar.

Works now.
Sorry, I should have seen the integer parameter issue ...