gpt4 book ai didi

sql - 使用select sql语句过滤表数据

转载 作者:行者123 更新时间:2023-12-04 14:41:40 24 4
gpt4 key购买 nike

我想使用 select 语句过滤表数据,我有四列,我还有四个文本框可以在每一列中启用搜索,我可以在任何框中输入值,当我在文本中输入值时box(es) 我想返回与我输入的值匹配的记录,我该怎么做?

ALTER PROCEDURE dbo.test_search

(
@ID int,
@FirstName nvarchar(50),
@MiddleName nvarchar(50),
@LastName nvarchar(50)
)

AS
SELECT ID, FirstName, MiddleName, LastName
FROM StudentsInformation
WHERE (@ID IS NULL OR StudentsInformation.ID = @ID) AND
(@FirstName IS NULL OR StudentsInformation.FirstName = @FirstName )AND
(@MiddleName IS NULL OR StudentsInformation.MiddleName = @MiddleName )AND
(@LastName IS NULL OR StudentsInformation.LastName = @LastName )
RETURN

最佳答案

编辑:

SELECT 
id
, firstname
, middlename
, lastname
FROM studentsinformation
WHERE id = @id
OR firstname LIKE '%' + @firstname + '%'
OR middlename LIKE '%' + @middlename + '%'
OR lastname LIKE '%' + @lastname + '%'

如果您想选择对所有复选框都为真的记录,您可以将 OR 换成 AND。

关于sql - 使用select sql语句过滤表数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16185584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com