开发者

SQL Server 2008 SMS vs Visual Studio 2010 Server Explorer results

i am having a problem with my SQL query that I wrote in Sql Server 2008 Express SMS and 开发者_StackOverflow中文版am using inside of Visual Studio 2010.

Basics: There is an input box on a web page. It is used to search for a persons name, address, id, etc. When I use a persons name on the website, or inside of the built in Visual Studio Server Explorer, such as "Kargul" (made up), it won't return any results using my Stored Procedure. However, in SQL Server 2008 Express SMS, the same Stored Procedure returns a valid result.

Is there something I am missing? Here is my Procedure:

SET NOCOUNT ON;

DECLARE @vars NVARCHAR(50);
SET @vars = '%' + @searchTerm + '%';

SELECT a.PersonId, Stat.StatusId, a.Honorific, a.FirstName, a.LastName, a.Street1, a.Street2, a.City, a.State, a.Zip, a.Phone, a.Email FROM Persons AS a
JOIN dbo.PersonStatus as Stat
ON a.StatusId = Stat.StatusId
    WHERE
        a.FirstName LIKE (@vars)
        UNION
        SELECT a.PersonId, Stat.StatusId, a.Honorific, a.FirstName, a.LastName, a.Street1, a.Street2, a.City, a.State, a.Zip, a.Phone, a.Email FROM Persons AS a
            JOIN dbo.PersonStatus as Stat
            ON a.StatusId = Stat.StatusId
                WHERE
        a.LastName LIKE (@vars)
        UNION
        SELECT a.PersonId, Stat.StatusId, a.Honorific, a.FirstName, a.LastName, a.Street1, a.Street2, a.City, a.State, a.Zip, a.Phone, a.Email FROM Persons AS a
            JOIN dbo.PersonStatus as Stat
            ON a.StatusId = Stat.StatusId
                WHERE
        a.Street1 LIKE (@vars)
        UNION
        SELECT a.PersonId, Stat.StatusId, a.Honorific, a.FirstName, a.LastName, a.Street1, a.Street2, a.City, a.State, a.Zip, a.Phone, a.Email FROM Persons AS a
            JOIN dbo.PersonStatus as Stat
            ON a.StatusId = Stat.StatusId
                WHERE
        a.City LIKE (@vars)
        UNION
        SELECT a.PersonId, Stat.StatusId, a.Honorific, a.FirstName, a.LastName, a.Street1, a.Street2, a.City, a.State, a.Zip, a.Phone, a.Email FROM Persons AS a
            JOIN dbo.PersonStatus as Stat
            ON a.StatusId = Stat.StatusId
                WHERE
        a.PersonId LIKE (@vars)
        UNION
        SELECT a.PersonId, Stat.StatusId, a.Honorific, a.FirstName, a.LastName, a.Street1, a.Street2, a.City, a.State, a.Zip, a.Phone, a.Email FROM Persons AS a
            JOIN dbo.PersonStatus as Stat
            ON a.StatusId = Stat.StatusId
                WHERE
        a.State LIKE (@vars)
    ORDER BY PersonId;


Run a profiler trace on the server to see what is executing when run through VS2010; Is it possible the search parameter is not getting passed? Or maybe you need a SET NOCOUNT ON in your proc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜