如何将存储过程转换为 SQL Server Compact Edition 查询 [英] How to convert stored procedure to SQL Server Compact Edition query

查看:38
本文介绍了如何将存储过程转换为 SQL Server Compact Edition 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要转换为标准查询的存储过程.由于我使用的是 SQL Server Compact,因此没有存储过程.

I have a stored procedure that I need to convert to a standard query. Since I'm using SQL Server Compact, no stored procedures.

这是我的存储过程:

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

就像我说的,我有点被难住了.有什么想法吗?

Like I say, I'm kind of stumped here. Any ideas?

推荐答案

这里是我用来确定时间值和动态指定列名的代码:

Here is the code that I used to determine the time value and dynamically specify the column name:

            float basalrate = 0;
        DateTime HourVal = Convert.ToDateTime(PumpEditTime);
        if (HourVal == null)
        {
            HourVal = DateTime.Now;
        }
        int hourval = HourVal.Hour;
        int ampmhour = Convert.ToInt32(HourVal.ToString("hh"));
        string hourampm = string.Empty;

        if (hourval == Convert.ToInt32("24"))
        {
            hourampm = "[12:00AM(00:00)]";
        }
        else if ((hourval > 12) && (hourval < 24))
        {
            hourampm = "[" + ampmhour + ":00PM(" + hourval + ":00)]";
        }
        else if (hourval == 12)
        {
            hourampm = "[12:00PM(12:00)]";
        }
        else if ((hourval < 12) && (hourval > 9))
        {
            hourampm = "[" + ampmhour + ":00AM(" + hourval + ":00)]";
        }
        else
        {
            hourampm = "[" + ampmhour + ":00AM(0" + hourval + ":00)]";
        }

这篇关于如何将存储过程转换为 SQL Server Compact Edition 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆