SQL Server 2008 SMS 与 Visual Studio 2010 服务器资源管理器结果

发布于 2024-11-04 18:40:03 字数 2239 浏览 0 评论 0原文

我在 Sql Server 2008 Express SMS 中编写并在 Visual Studio 2010 中使用的 SQL 查询出现问题。

基础知识:网页上有一个输入框。它用于搜索人名、地址、ID 等。当我在网站上或内置 Visual Studio Server Explorer 中使用人名时,例如“Kargul”(编造的),它不会使用我的存储过程不会返回任何结果。 但是,在 SQL Server 2008 Express SMS 中,相同的存储过程返回有效结果。

我有什么遗漏的吗?这是我的程序:

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;

i am having a problem with my SQL query that I wrote in Sql Server 2008 Express SMS and 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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北恋 2024-11-11 18:40:03

在服务器上运行探查器跟踪,以查看在 VS2010 中运行时正在执行什么;是否有可能搜索参数没有被传递?或者也许您需要在您的过程中设置 SET NOCOUNT ON。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文