本文介绍了如何循环我的同一个声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何缩短100条Nation_code和Description不同记录的声明。
示例: -
INSERT INTO @SHY_DT
选择说明,
ISNULL(COUNT(数量),0),
ISNULL(SUM(数量),0)
来自M_Master
WHERE
scode = @BMSCode
AND
Nation_Code = Ncode
我的餐桌
Ncode说明
MYS Malaysia
SGP新加坡
CHN China
......
我的尝试:
目前,我的声明如下
How to shorten the my statement for 100 records different of Nation_code and Description.
Example:-
INSERT INTO @SHY_DT
SELECT Description,
ISNULL(COUNT(Quantity),0),
ISNULL(SUM(Quantity),0)
FROM M_Master
WHERE
scode = @BMSCode
AND
Nation_Code = Ncode
My Table
Ncode Description
MYS Malaysia
SGP Singapore
CHN China
......
What I have tried:
Currently, My statement as below
INSERT INTO @SHY_DT
SELECT Description,
ISNULL(COUNT(Quantity),0),
ISNULL(SUM(Quantity),0)
FROM M_Master
WHERE
scode = @BMSCode
AND
Nation_Code = 'MYS'
;
INSERT INTO @SHY_DT
SELECT 'MALAYSIA',
ISNULL(COUNT(Quantity),0),
ISNULL(SUM(Quantity),0)
FROM M_Master
WHERE
scode = @BMSCode
AND
Nation_Code = 'MYS'
;
INSERT INTO @SHY_DT
SELECT 'SINGAPORE',
ISNULL(COUNT(Quantity),0),
ISNULL(SUM(Quantity),0)
FROM M_Master
WHERE
s_code = @BMSCode
AND
Nation_Code = 'SGP'
;
INSERT INTO @SHY_DT
SELECT.....
推荐答案
这篇关于如何循环我的同一个声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!