高分悬赏 请大神指导-超级长得SQL语句,看晕你的头,求大神帮忙看一下这段SQL错在哪里。

问题描述

超级长得SQL语句,看晕你的头,求大神帮忙看一下这段SQL错在哪里。
                        DECLARE @SQL VARCHAR(8000)
                        SET @SQL ='SELECT A.POINT,
                           A.WZ,
                           A.LC,
                           A.PL1,
                           A.PL2,
                           A.XS1,
                           CASE
                               WHEN ISNULL(A.ZDZS,'''') <> '''' THEN A.ZDZS
                               ELSE 0
                           END AS ZDZS,
                           CASE
                               WHEN ISNULL(A.PJZ,'''') <> '''' THEN A.PJZ
                               ELSE 0
                           END AS PJZ,
                           CASE
                               WHEN ISNULL(A.SSZ,'''') <> '''' THEN A.SSZ
                               ELSE 0
                           END AS SSZ,
                           CASE
                               WHEN ISNULL(A.ZXZ,'''') <> '''' THEN A.ZXZ
                               ELSE 0
                           END AS ZXZ,
                           CASE
                               WHEN ISNULL(A.ZXZS,'''') <> '''' THEN A.ZXZS
                               ELSE 0
                           END AS ZXZS,
                           CASE
                               WHEN ISNULL(A.ZDZ,'''') <> '''' THEN A.ZDZ
                               ELSE 0
                           END AS ZDZ,
                           CASE
                               WHEN ISNULL(A.MaximumAndTime,'''') <> '''' THEN A.MaximumAndTime
                               ELSE CONVERT(VARCHAR(50),GETDATE(),20)
                           END AS MaximumAndTime,

                         A.SJ  双击后错误指向这里 为 消息 102,级别 15,状态 1,第 36 行

')' 附近有语法错误。

                    FROM('
                        SET @SQL= @SQL + 'SELECT * FROM ('
                        IF OBJECT_ID('FC_M20140608', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-08 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               0 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               0* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               0* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140608 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140609', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-09 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               1 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               1* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               1* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140609 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140610', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-10 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               2 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               2* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               2* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140610 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140611', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-11 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               3 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               3* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               3* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140611 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140612', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-12 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               4 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               4* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               4* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140612 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140613', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-13 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               5 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               5* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               5* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140613 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140614', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-14 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               6 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               6* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               6* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140614 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140615', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-15 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               7 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               7* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               7* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140615 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140616', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-16 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               8 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               8* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               8* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140616 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140617', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-17 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               9 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               9* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               9* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140617 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140618', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-18 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               10 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               10* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               10* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140618 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140619', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-19 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               11 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               11* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               11* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140619 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            IF OBJECT_ID('FC_M20140620', 'U') IS NOT NULL
                            BEGIN
                               SET @SQL = @SQL + 'SELECT ''001A07'' AS POINT,
                               wz.WZ,
                               dev.LC,
                               dev.PL1,
                               dev.PL2,
                               dev.XS1,
                               CONVERT(varchar(50),m.ZDZ) +''2014-06-20 ''+ CONVERT(varchar(50),m.ZDZS / 3600)+'':''+ CONVERT(varchar(50),(m.ZDZS % 3600)/60)+'':''+CONVERT(varchar(50),(m.ZDZS % 3600) % 60) AS MaximumAndTime,
                               12 * 86400 + m.ZDZS AS ZDZS,
                               m.PJZ,
                               12* 1440 + m.SJ AS SJ,
                               SSZ,
                               ZXZ,
                               12* 86400 + m.ZXZS AS ZXZS,
                               m.ZDZ
                        FROM   FC_M20140620 m INNER
                        JOIN   FC_DEV dev
                          ON   m.DEVID = dev.DEVID
                          INNER
                        JOIN   FC_WZ wz
                          ON   m.WZID = wz.WZID
                        WHERE  m.FZH = 001
                          AND  m.KH = 07 UNION ALL '
                            END
                            SET @SQL = SUBSTRING(@SQL,1,(LEN(@SQL)- 9))
                        SET @SQL = @SQL + ') F) A  ORDER BY SJ '
                        EXEC(@SQL)
时间: 2024-09-30 15:38:26

高分悬赏 请大神指导-超级长得SQL语句,看晕你的头,求大神帮忙看一下这段SQL错在哪里。的相关文章

app-Android通过jtds连接mssql,如何判断是否连接成功和执行sql语句后是否为空,求大神指教

问题描述 Android通过jtds连接mssql,如何判断是否连接成功和执行sql语句后是否为空,求大神指教 连接实例已经学会啦,但app启动后只能等待超时来判断是否连接到mssql,可如果sql语句执行后为空记录的话也只能等连接超时才能知道,我不知道如何做这两项判断,麻烦知道的给我写下实例好吗? 解决方案 http://blog.sina.com.cn/s/blog_60b5e13e0101mlot.html 解决方案二: http://www.2cto.com/database/20141

图片-悬赏40分 全英文的介绍的简单的两个c语言编程 求大神帮忙解答

问题描述 悬赏40分 全英文的介绍的简单的两个c语言编程 求大神帮忙解答 解决方案 #include int main() { int count; printf("输入"*"的个数:"); scanf("%d",&count); for(int i=0;i<=count;i++) { for(int j=0;j<i;j++) { printf("*"); } printf("n");

sql server2008建立连接出现错误,求大神指教,在线等,急!!!

问题描述 sql server2008建立连接出现错误,求大神指教,在线等,急!!! 无法连接到 local. 其他信息: 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) (Microsoft SQL Server,错误: 53)

方法-关于return语句的一个小白问题,求大神帮助!

问题描述 关于return语句的一个小白问题,求大神帮助! namespace ConsoleApplication34 { class Program { static string k(string b) { string a; a = "你的名字是" +b; return a; } static void Main(string[] args) { Console.WriteLine("输入姓名"); string c = Console.ReadLine()

网页网页,跪求大神。HTML加CSS做的网页二级界面,跪求大神帮忙。

问题描述 网页网页,跪求大神.HTML加CSS做的网页二级界面,跪求大神帮忙. HTML加CSS做的网页二级界面,跪求大神帮忙.HTML加CSS做的网页二级界面,跪求大神帮忙. 解决方案 问的什么问题 啊?具体你那里出现问题.

android-Android通过jtds连接sql,加载驱动程序出错,求大神指教

问题描述 Android通过jtds连接sql,加载驱动程序出错,求大神指教 import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import android.app.Activity; import android.database.SQLException; import android.os.Bundle; impor

sql server-跨数据库同步数据的问题 求大神指点

问题描述 跨数据库同步数据的问题 求大神指点 我有两台服务器 一台是以sql身份验证用户名密码登陆的 内有两个在持续写入新数据的表1和2 两个表同时写入 具有相同的格式为datetime2(7)的列为主键 没有id列 另一台服务器是以windows身份验证登陆的 有一个表3 现在想要把表1的A B C三列的值.表2的D E两列的值同时分别插入到表3的b d f和c e列当中并且之后连续的将表1表2新增的数据插入 应该如何实现 解决方案 写两套连接 创建两个sqlsession 然后对两个不同库进

高分悬赏 请大神指导-网上发现找到一组c语言代码,求帮忙整合成能用

问题描述 网上发现找到一组c语言代码,求帮忙整合成能用 #include #include #include #include #ifndef FUNCTION_H#define _FUNCITON_H_typedef struct student{ char nameStudent[10]; int numberSudent; int indexN; //已选数量 int elect[20]; //已选课题编号(多个) BOOL whetherNull;}STU;typedef struct

高分悬赏 请大神指导-VBA高手请进 懂得webbrowser

问题描述 VBA高手请进 懂得webbrowser 请问如何通过VBA能够获取网页弹出窗体的Docuement对象,我是要操作弹出窗体里面的一线控件完成自动复制! 我现在可以获取到主页面的Document对象.