Sql用变量拼语句
时间:2021-07-01 10:21:17
帮助过:2人阅读
PROC Test_GetCollegeInfo
@type int
AS
BEGIN
DECLARE @where nvarchar(
800),
@v int,
@sql nvarchar(
max)
IF @type>2
Begin
SET @where=‘AND colleges.id=‘+cast(
@type AS varchar(
100))
END
ELSE
BEGIN
SET @where=‘‘
END
SET @sql=‘
SELECT * FROM collegeMajor
INNER JOIN MajorsType ON collegeMajor.majorType=MajorsType.id
INNER JOIN colleges ON colleges.id=collegeMajor.collageID
WHERE 1=1 ‘+@where
EXEC (
@sql)
End
Sql用变量拼语句
标签: