首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql查询语句的转换有关问题

2013-03-01 
sql查询语句的转换问题CREATE PROCEDURE Proc_tbTareSelectAll-- Add the parameters for the stored proc

sql查询语句的转换问题
CREATE PROCEDURE Proc_tbTareSelectAll
-- Add the parameters for the stored procedure here
@strWhere nvarchar(255)=null
AS
BEGIN 
begin
SELECT [TareID]  as 序号
      ,[CarID] as 车号
      ,[StationID] as 站点
      ,[TARE] as 皮重
      ,[TRWID] as 任务号
      ,[TareLu] as 路数
      ,[TareStated]  as 皮重状态
      ,[TaredSetCount] as 设定次数
      ,[TaredCount] as 实过次数
      ,[Tmemos] as 备注
    FROM [OneWeight].[CarScale].[tbTare] 
    where + @strWhere    --这个地方怎么写呢
go
[解决办法]

CREATE PROCEDURE Proc_tbTareSelectAll
-- Add the parameters for the stored procedure here
@strWhere nvarchar(255)=null
AS
BEGIN 
DECLARE @sql NVARCHAR(500)
SET @sql = 'SELECT [TareID]  as 序号
      ,[CarID] as 车号
      ,[StationID] as 站点
      ,[TARE] as 皮重
      ,[TRWID] as 任务号
      ,[TareLu] as 路数
      ,[TareStated]  as 皮重状态
      ,[TaredSetCount] as 设定次数
      ,[TaredCount] as 实过次数
      ,[Tmemos] as 备注
    FROM [OneWeight].[CarScale].[tbTare] 
    where ' + @strWhere    --比如@strwhere 内容是 tarelu='20'
    
    EXEC(@sql)
END

[解决办法]
CREATE PROCEDURE Proc_tbTareSelectAll
-- Add the parameters for the stored procedure here
@strWhere nvarchar(255)=null
AS
DECLARE @sql NVARCHAR(max)
SET @sql='SELECT [TareID]  as 序号
      ,[CarID] as 车号
      ,[StationID] as 站点
      ,[TARE] as 皮重
      ,[TRWID] as 任务号
      ,[TareLu] as 路数
      ,[TareStated]  as 皮重状态
      ,[TaredSetCount] as 设定次数
      ,[TaredCount] as 实过次数
      ,[Tmemos] as 备注
    FROM [OneWeight].[CarScale].[tbTare] 
    where '+ @strWhere    --这个地方怎么写呢
    EXEC (@sql)
go
 

热点排行
Bad Request.