Click here to Skip to main content
15,924,901 members
Home / Discussions / Database
   

Database

 
AnswerRe: ADO.NET started with what version of ADO? Pin
Colin Angus Mackay15-Mar-06 10:41
Colin Angus Mackay15-Mar-06 10:41 
GeneralRe: ADO.NET started with what version of ADO? Pin
LuluSailor17-Mar-06 6:27
LuluSailor17-Mar-06 6:27 
QuestionMuiltiple SQL Join tutorials Pin
Chandana Subasinghe15-Mar-06 2:17
Chandana Subasinghe15-Mar-06 2:17 
AnswerRe: Muiltiple SQL Join tutorials Pin
albCode15-Mar-06 2:38
albCode15-Mar-06 2:38 
GeneralRe: Muiltiple SQL Join tutorials Pin
Chandana Subasinghe15-Mar-06 5:48
Chandana Subasinghe15-Mar-06 5:48 
AnswerRe: Muiltiple SQL Join tutorials Pin
HimaBindu Vejella15-Mar-06 19:13
HimaBindu Vejella15-Mar-06 19:13 
QuestionHow to backup data from Online WebServer to My local Server Pin
Rajkamal_dfine14-Mar-06 21:17
Rajkamal_dfine14-Mar-06 21:17 
QuestionNeed help with stored procedure in where clause. Pin
Slow Learner14-Mar-06 9:17
Slow Learner14-Mar-06 9:17 
Hello,
I am using SQL Server 2005 and I am just wondering if I can build the WHERE clause dynamically. I only want to build WHERE class if the my @VIN count is of exactly 17 charecters. Here is my code
*************************************************
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[SP_SearchGroundedVehicles]
@vin varchar(17)
AS
BEGIN
SET NOCOUNT ON;

SELECT V.vin
,C.FirstName
,C.LastName
,C.AccountNum
,D.DealerShipName
,Contrt.MaturityDate
FROM ContractInfo Contrt
Inner Join VehicleInformation V ON Contrt.VehicleID = V.VehicleID
Inner Join DealerShips D ON Contrt.DealerShipID = D.DealerShipID
Inner Join Customer C ON Contrt.CustomerID = C.CustomerID
if count(@vin) = 17
begin
Where VIN = @VIn
end

END
*******************************************************
But when I parse the above stored proc its throwing this message


********
Msg 156, Level 15, State 1, Procedure SP_SearchGroundedVehicles, Line 33
Incorrect syntax near the keyword 'Where'.
********


If it is possible to dynamically build WHERE clause please correct the way I am doing it or if it is not possible what is the best way of writing it?

Thanks
-L
AnswerRe: Need help with stored procedure in where clause. Pin
Michael Potter14-Mar-06 9:32
Michael Potter14-Mar-06 9:32 
GeneralRe: Need help with stored procedure in where clause. Pin
Slow Learner14-Mar-06 11:34
Slow Learner14-Mar-06 11:34 
GeneralRe: Need help with stored procedure in where clause. Pin
Michael Potter15-Mar-06 3:21
Michael Potter15-Mar-06 3:21 
QuestionRetrieve Value from DetailsView Pin
Armando_Ramirez14-Mar-06 7:41
Armando_Ramirez14-Mar-06 7:41 
QuestionUpdate Dates in SQL Pin
Illegal Operation14-Mar-06 1:10
Illegal Operation14-Mar-06 1:10 
AnswerRe: Update Dates in SQL Pin
albCode14-Mar-06 4:34
albCode14-Mar-06 4:34 
GeneralRe: Update Dates in SQL Pin
Illegal Operation14-Mar-06 17:23
Illegal Operation14-Mar-06 17:23 
AnswerRe: Update Dates in SQL Pin
Chris Meech15-Mar-06 7:02
Chris Meech15-Mar-06 7:02 
QuestionPassing arguments for stored procedures IN Pin
BSRK14-Mar-06 1:01
BSRK14-Mar-06 1:01 
AnswerRe: Passing arguments for stored procedures IN Pin
BSRK14-Mar-06 1:19
BSRK14-Mar-06 1:19 
AnswerRe: Passing arguments for stored procedures IN Pin
Colin Angus Mackay14-Mar-06 1:27
Colin Angus Mackay14-Mar-06 1:27 
AnswerRe: Passing arguments for stored procedures IN Pin
Colin Angus Mackay14-Mar-06 1:29
Colin Angus Mackay14-Mar-06 1:29 
AnswerRe: Passing arguments for stored procedures IN Pin
Eric Dahlvang14-Mar-06 4:45
Eric Dahlvang14-Mar-06 4:45 
GeneralRe: Passing arguments for stored procedures IN Pin
Colin Angus Mackay14-Mar-06 21:44
Colin Angus Mackay14-Mar-06 21:44 
QuestionReturn 0 Pin
Brendan Vogt14-Mar-06 0:44
Brendan Vogt14-Mar-06 0:44 
AnswerRe: Return 0 Pin
Michael Potter14-Mar-06 9:36
Michael Potter14-Mar-06 9:36 
QuestionDB_E_DATAFIELD_OVERFLOW Error Pin
Gupta Suraj14-Mar-06 0:14
Gupta Suraj14-Mar-06 0:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.