Click here to Skip to main content
15,909,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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..... 
Posted
Updated 7-Feb-18 22:19pm
Comments
Maciej Los 8-Feb-18 4:08am    
Sorry, but your question is unclear. Please, be more specific and provide more datails about your issue.

1 solution

I'm not sure what you want to achieve, but it seems you want to join data from two tables and insert them into another.

Please, check this: How do I make a INNER JOIN inside a INSERT INTO statement?[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900