我正在尝试使用企业管理器在 SQL Server 2000 中创建视图

发布于 2024-11-17 16:52:18 字数 3319 浏览 0 评论 0原文

我正在尝试使用企业管理器在 SQL Server 2000 中创建一个视图,有时它不会返回任何行,当它不返回时,我需要它返回 0。 我已经尝试过此操作,但当我尝试保存它时,我不断收到此消息:

查询设计器不支持 IF SQL 构造。

IF EXISTS (SELECT     dbo.oehdrhst_sql.cus_no, dbo.oehdrhst_sql.inv_dt, dbo.oehdrhst_sql.inv_no, dbo.OELINHST_SQL.item_no, 
                                          dbo.OELINHST_SQL.item_desc_1, dbo.OELINHST_SQL.item_desc_2, dbo.OELINHST_SQL.qty_to_ship, dbo.IMITMIDX_SQL.user_def_fld_1, 
                                          dbo.IMITMIDX_SQL.user_def_fld_2, dbo.IMITMIDX_SQL.user_def_fld_3, dbo.IMITMIDX_SQL.user_def_fld_4, 
                                          dbo.IMITMIDX_SQL.user_def_fld_5, dbo.oehdrhst_sql.ord_type, dbo.oehdrhst_sql.orig_ord_type, dbo.OELINHST_SQL.qty_return_to_stk, 
                                          dbo.OELINHST_SQL.qty_to_ship * dbo.IMITMIDX_SQL.user_def_fld_2 AS extended, CONVERT(datetime, STR(dbo.oehdrhst_sql.inv_dt, 8, 0)) 
                                          AS [Date]
                    FROM         dbo.oehdrhst_sql INNER JOIN
                                          dbo.OELINHST_SQL ON dbo.oehdrhst_sql.ord_no = dbo.OELINHST_SQL.ord_no INNER JOIN
                                          dbo.IMITMIDX_SQL ON dbo.OELINHST_SQL.item_no = dbo.IMITMIDX_SQL.item_no
                    WHERE     (dbo.oehdrhst_sql.inv_dt BETWEEN 20100701 AND 20110630) AND (dbo.OELINHST_SQL.item_no BETWEEN '3065 0' AND 
                                          '3065 ZZZZZZZZZZ') AND (NOT (dbo.IMITMIDX_SQL.user_def_fld_2 IS NULL)))
SELECT     EXTENDED, cus_no, inv_dt, inv_no, item_no, item_desc_1, item_desc_2, qty_to_ship, user_def_fld_1, user_def_fld_2, [date]
 FROM         (SELECT     dbo.oehdrhst_sql.cus_no, dbo.oehdrhst_sql.inv_dt, dbo.oehdrhst_sql.inv_no, dbo.OELINHST_SQL.item_no, 
                                               dbo.OELINHST_SQL.item_desc_1, dbo.OELINHST_SQL.item_desc_2, dbo.OELINHST_SQL.qty_to_ship, 
                                               dbo.IMITMIDX_SQL.user_def_fld_1, dbo.IMITMIDX_SQL.user_def_fld_2, dbo.IMITMIDX_SQL.user_def_fld_3, 
                                               dbo.IMITMIDX_SQL.user_def_fld_4, dbo.IMITMIDX_SQL.user_def_fld_5, dbo.oehdrhst_sql.ord_type, dbo.oehdrhst_sql.orig_ord_type, 
                                               dbo.OELINHST_SQL.qty_return_to_stk, dbo.OELINHST_SQL.qty_to_ship * dbo.IMITMIDX_SQL.user_def_fld_2 AS extended, 
                                               CONVERT(datetime, STR(dbo.oehdrhst_sql.inv_dt, 8, 0)) AS [Date]
                        FROM          dbo.oehdrhst_sql INNER JOIN
                                               dbo.OELINHST_SQL ON dbo.oehdrhst_sql.ord_no = dbo.OELINHST_SQL.ord_no INNER JOIN
                                               dbo.IMITMIDX_SQL ON dbo.OELINHST_SQL.item_no = dbo.IMITMIDX_SQL.item_no
                        WHERE      (dbo.oehdrhst_sql.inv_dt BETWEEN 20100701 AND 20110630) AND (dbo.OELINHST_SQL.item_no BETWEEN '3065 0' AND 
                                               '3065 ZZZZZZZZZZ') AND (NOT (dbo.IMITMIDX_SQL.user_def_fld_2 IS NULL))) a
 GROUP BY EXTENDED, cus_no, inv_dt, inv_no, item_no, item_desc_1, item_desc_2, qty_to_ship, user_def_fld_1, user_def_fld_2, [date] ELSE
                            SELECT     EXTENDED = 0

I am trying to creat a View in SQL server 2000 using the Enterprise Manager that some times doesn't return any rows and when it doesn't i need it to return a 0.
I have tried this but I keep getting this message when I try to save it:

The Query Designer does not support
the IF SQL construct.

IF EXISTS (SELECT     dbo.oehdrhst_sql.cus_no, dbo.oehdrhst_sql.inv_dt, dbo.oehdrhst_sql.inv_no, dbo.OELINHST_SQL.item_no, 
                                          dbo.OELINHST_SQL.item_desc_1, dbo.OELINHST_SQL.item_desc_2, dbo.OELINHST_SQL.qty_to_ship, dbo.IMITMIDX_SQL.user_def_fld_1, 
                                          dbo.IMITMIDX_SQL.user_def_fld_2, dbo.IMITMIDX_SQL.user_def_fld_3, dbo.IMITMIDX_SQL.user_def_fld_4, 
                                          dbo.IMITMIDX_SQL.user_def_fld_5, dbo.oehdrhst_sql.ord_type, dbo.oehdrhst_sql.orig_ord_type, dbo.OELINHST_SQL.qty_return_to_stk, 
                                          dbo.OELINHST_SQL.qty_to_ship * dbo.IMITMIDX_SQL.user_def_fld_2 AS extended, CONVERT(datetime, STR(dbo.oehdrhst_sql.inv_dt, 8, 0)) 
                                          AS [Date]
                    FROM         dbo.oehdrhst_sql INNER JOIN
                                          dbo.OELINHST_SQL ON dbo.oehdrhst_sql.ord_no = dbo.OELINHST_SQL.ord_no INNER JOIN
                                          dbo.IMITMIDX_SQL ON dbo.OELINHST_SQL.item_no = dbo.IMITMIDX_SQL.item_no
                    WHERE     (dbo.oehdrhst_sql.inv_dt BETWEEN 20100701 AND 20110630) AND (dbo.OELINHST_SQL.item_no BETWEEN '3065 0' AND 
                                          '3065 ZZZZZZZZZZ') AND (NOT (dbo.IMITMIDX_SQL.user_def_fld_2 IS NULL)))
SELECT     EXTENDED, cus_no, inv_dt, inv_no, item_no, item_desc_1, item_desc_2, qty_to_ship, user_def_fld_1, user_def_fld_2, [date]
 FROM         (SELECT     dbo.oehdrhst_sql.cus_no, dbo.oehdrhst_sql.inv_dt, dbo.oehdrhst_sql.inv_no, dbo.OELINHST_SQL.item_no, 
                                               dbo.OELINHST_SQL.item_desc_1, dbo.OELINHST_SQL.item_desc_2, dbo.OELINHST_SQL.qty_to_ship, 
                                               dbo.IMITMIDX_SQL.user_def_fld_1, dbo.IMITMIDX_SQL.user_def_fld_2, dbo.IMITMIDX_SQL.user_def_fld_3, 
                                               dbo.IMITMIDX_SQL.user_def_fld_4, dbo.IMITMIDX_SQL.user_def_fld_5, dbo.oehdrhst_sql.ord_type, dbo.oehdrhst_sql.orig_ord_type, 
                                               dbo.OELINHST_SQL.qty_return_to_stk, dbo.OELINHST_SQL.qty_to_ship * dbo.IMITMIDX_SQL.user_def_fld_2 AS extended, 
                                               CONVERT(datetime, STR(dbo.oehdrhst_sql.inv_dt, 8, 0)) AS [Date]
                        FROM          dbo.oehdrhst_sql INNER JOIN
                                               dbo.OELINHST_SQL ON dbo.oehdrhst_sql.ord_no = dbo.OELINHST_SQL.ord_no INNER JOIN
                                               dbo.IMITMIDX_SQL ON dbo.OELINHST_SQL.item_no = dbo.IMITMIDX_SQL.item_no
                        WHERE      (dbo.oehdrhst_sql.inv_dt BETWEEN 20100701 AND 20110630) AND (dbo.OELINHST_SQL.item_no BETWEEN '3065 0' AND 
                                               '3065 ZZZZZZZZZZ') AND (NOT (dbo.IMITMIDX_SQL.user_def_fld_2 IS NULL))) a
 GROUP BY EXTENDED, cus_no, inv_dt, inv_no, item_no, item_desc_1, item_desc_2, qty_to_ship, user_def_fld_1, user_def_fld_2, [date] ELSE
                            SELECT     EXTENDED = 0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

‘画卷フ 2024-11-24 16:52:18

您可以删除 IF EXISTS 部分并仅使用 ISNULL(EXTENDED,0)。但这假设了很多。

You can probably drop the IF EXISTS portion and just use an ISNULL(EXTENDED,0). That assumes a lot though.

太阳男子 2024-11-24 16:52:18

这不是您应该在视图中执行的操作。相反,当您调用视图时执行此操作,即:

IF (SELECT COUNT(*) FROM v_MyView) > 0
BEGIN
   SELECT * FROM v_MyView
END 
ELSE
SELECT 0

This is not something you should do in the view. Instead do it when you CALL the view, i.e.:

IF (SELECT COUNT(*) FROM v_MyView) > 0
BEGIN
   SELECT * FROM v_MyView
END 
ELSE
SELECT 0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文