Error in Insert statement
-
Hello, I have the following procedure CREATE PROCEDURE tryproc AS declare @first int; select sum(t) as first from demand where product='LPG' AND LOCATION = 'Mumbai'; create table abc (demandsum int); insert into abc (demandsum) values (@first); In the above procedure the value inserted in te table is NULL. I want the sum got from the table to be inserted in the table abc. What must be the problem? Prithaa
-
Hello, I have the following procedure CREATE PROCEDURE tryproc AS declare @first int; select sum(t) as first from demand where product='LPG' AND LOCATION = 'Mumbai'; create table abc (demandsum int); insert into abc (demandsum) values (@first); In the above procedure the value inserted in te table is NULL. I want the sum got from the table to be inserted in the table abc. What must be the problem? Prithaa
prithaa wrote:
What must be the problem?
Problem is you are not assigning the variable value. See this and rewrite it
CREATE PROCEDURE tryproc
AS
DECLARE @first INT
SET @first = ( SELECT SUM(t) AS first
FROM demand
WHERE product = 'LPG'
AND LOCATION = 'Mumbai' )
CREATE TABLE abc (demandsum INT)
INSERT INTO abc (demandsum) VALUES (@first)Hope it helps
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
Hello, I have the following procedure CREATE PROCEDURE tryproc AS declare @first int; select sum(t) as first from demand where product='LPG' AND LOCATION = 'Mumbai'; create table abc (demandsum int); insert into abc (demandsum) values (@first); In the above procedure the value inserted in te table is NULL. I want the sum got from the table to be inserted in the table abc. What must be the problem? Prithaa
Hi, you can use this query ... however you can reduce the no. of DML stm.. SELECT dem.first INTO abc FROM (SELECT SUM(t) AS first FROM demand WHERE product = 'LPG' AND LOCATION = 'Mumbai' ) dem