我有一个需要转换为标准查询的存储过程。由于我使用的是 SQL Server Compact,因此没有存储过程。
这是我的存储过程:
declare @colu nvarchar (max) , @hour int
set @hour = DATEPART(HH, GETDATE() )
select @hour
select @colu =
case when @hour=24
then '[12:00AM(00:00)]'
enter code here
when @hour >12 and @hour <24
then '['+ convert(varchar,@hour-12) +':00PM('+ convert(nvarchar ,@hour) +':00)]'
when @hour=12
then '[12:00PM(12:00)]'
when @hour <12 and @hour >9
then '['+convert(nvarchar ,@hour) +':00AM('+ convert(nvarchar ,@hour) +':00)]'
else '['+convert(nvarchar ,@hour) +':00AM(0'+ convert(nvarchar ,@hour) +':00)]'
end
select @colu
declare @sql nvarchar(max)
set @sql= 'select ID,'''+ @colu + ''' as time from table' -- add quote here
select @sql
exec sp_executesql @sql
就像我说的,我在这里有点难过。有任何想法吗?