Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Error in Insert statement

Error in Insert statement

Scheduled Pinned Locked Moved Database
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    prithaa
    wrote on last edited by
    #1

    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

    N D 2 Replies Last reply
    0
    • P 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

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • P 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

        D Offline
        D Offline
        Devan Nadar
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups