Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Invalid Column Name error
Message
 
 
À
11/11/2010 11:22:05
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01488773
Message ID:
01488822
Vues:
27
>Naomi,
>
>What would I need to do to accomodate the Student ID from being null or the TutorID from being an empty string?
>Thanks
>

That's a very interesting question and I suggest you to read Dynamic Search condition article I gave you a link yesterday.

I was re-reading it quickly myself yesterday night.

One of the direct possibilities is to use IF code.

IF @StudentID IS NULL and @TutorIDs IS NOT NULL
One query

IF @StudentID IS NOT NULL and @TutorIDs IS NULL
Another query

IF both not null

your current query

IF both null

raiserror

But you will need to add OPTIMIZE hint.

Erland explains it very well in his article, so I suggest you to start reading.


>>You're missing a closing ) in your code
>>
>>WHERE 
>>		TutorID IN (SELECT Value from dbo.fnSplit(@TutorIDs, ',') -- here we need to add one more )
>>
>>
>>I also don't like IN solution that much. I prefer using EXISTS operator.
>>
>>>>>Ah, well I didn't mean to. I just copy and pasted in and it worked. Thanks
>>>>>Tim
>>>>>
>>>>You're welcome. I will be curious if you can compare 3 versions of the query: your original and 2 versions I posted and tell me the execution plans and percentage.
>>>>
>>>>Put all 3 queries (after a correction to your original) into one sql script and run them
>>>>
>>>>set nocount on
>>>>set statistics io on
>>>>set statistics time on
>>>>query 1
>>>>query 2
>>>>query 3
>>>>
>>>>
>>>>and post the results as well as percentage of execution time from the actual execution plan.
>>>
>>>
>>>Hi Naomi,
>>>
>>>I doubt that would be useful as I only have test data plus this query pulls no more than a few records. I would be happy to do it however.
>>>
>>>Now I do have a problem with the query that uses the function. I have this error.
>>>
>>>Msg 156, Level 15, State 1, Procedure AppointmentsSelectByTutorsPlusStudentID, Line 19
>>>Incorrect syntax near the keyword 'OR'.
>>>
>>>
>>>With this SP
>>>
>>>CREATE PROCEDURE [dbo].[AppointmentsSelectByTutorsPlusStudentID]
>>>(
>>>	@TutorIDs varchar(500),
>>>	@StudentID char(5)
>>>)
>>>AS
>>>BEGIN
>>>	SET NOCOUNT ON;
>>>	
>>>	SELECT 
>>>		AppointmentID,
>>>		TutorID,
>>>		Description
>>>	FROM [dbo].[Appointment]
>>>	WHERE 
>>>		TutorID IN (SELECT Value from dbo.fnSplit(@TutorIDs, ',') OR
>>>		AppointmentID IN (SELECT AppointmentID FROM StudentAppointments WHERE StudentID = @StudentID) 
>>>	
>>>END
>>>
>>>Thanks
>>>Tim
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform