Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 将查询从PLSQL写入SQ服务器_Sql Server_Plsql - Fatal编程技术网

Sql server 将查询从PLSQL写入SQ服务器

Sql server 将查询从PLSQL写入SQ服务器,sql-server,plsql,Sql Server,Plsql,我用PL/SQL编写了这个查询 if l_rec.sched_interval_type = 'DAYS' then if l_max_date is null then if l_rec.DAY_START_DAY is not null then SELECT next_day(p_date, l_rec.DAY_START_DAY) INTO l_start_date

我用PL/SQL编写了这个查询

if l_rec.sched_interval_type = 'DAYS' then    
    if l_max_date is null then       
        if l_rec.DAY_START_DAY is not null then     
            SELECT next_day(p_date, l_rec.DAY_START_DAY)    
            INTO l_start_date    
            FROM dual;    
        else    
            l_start_date := TRUNC(p_date);    
        end if;    
我尝试将其转换为SQL SERVER

set @NextDayID =(SELECT DAY_START_DAY FROM #l_rec )
SELECT  CASE WHEN sched_interval_type  = 'DAYS' then         
        CASE WHEN @l_max_date is null then     
        CASE WHEN  @NextDayID is not null then     
           @l_start_date  =  DATEADD(DAY, (DATEDIFF(DAY, ((@NextDayID + 5) % 7), GETDATE()) / 7) * 7 + 7, ((@NextDayID + 5) % 7))
        else    
           @l_start_date =CONVERT(DATETIME, CONVERT(DATE, @p_date))    
        end 
我有很多错误,如何改正

试试这个:

DECLARE @NextDayID INT
SELECT @NextDayID = DAY_START_DAY FROM #l_rec 

SELECT @l_start_date CASE WHEN sched_interval_type  = 'DAYS' and @l_max_date is null and  @NextDayID is not null then    
 DATEADD(DAY, (DATEDIFF(DAY, ((@NextDayID + 5) % 7), GETDATE()) / 7) * 7 + 7, ((@NextDayID + 5) % 7))
          else CONVERT(DATETIME, CONVERT(DATE, @p_date)) end as [start_date]
          from <<someTableName>> --<<--Replace the tag with the table whihc has the column `sched_interval_type`

如果您打算进行大量此类转换,本书非常有价值: