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. Is it possible to print a variable in stored procedure

Is it possible to print a variable in stored procedure

Scheduled Pinned Locked Moved Database
database
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.
  • D Offline
    D Offline
    Deepthi 21456
    wrote on last edited by
    #1

    I am adding my code below

    create procedure dist_profit_pairs1(IN user_id
    varchar(20),IN plan varchar(20))
    begin
    DECLARE left_bvs,right_bvs Float DEFAULT 0;
    SELECT sum(businessvalues)as left_bvs from bv_history where userid=user_id and type='Distribution Profit' and position='Left';
    SELECT sum(businessvalues)as right_bvs from bv_history where userid=user_id and type='Distribution Profit' and position='Right';

    IF left_bvs < right_bvs THEN
    SELECT left_bvs;
    ELSE
    SELECT right_bvs;

    N 1 Reply Last reply
    0
    • D Deepthi 21456

      I am adding my code below

      create procedure dist_profit_pairs1(IN user_id
      varchar(20),IN plan varchar(20))
      begin
      DECLARE left_bvs,right_bvs Float DEFAULT 0;
      SELECT sum(businessvalues)as left_bvs from bv_history where userid=user_id and type='Distribution Profit' and position='Left';
      SELECT sum(businessvalues)as right_bvs from bv_history where userid=user_id and type='Distribution Profit' and position='Right';

      IF left_bvs < right_bvs THEN
      SELECT left_bvs;
      ELSE
      SELECT right_bvs;

      N Offline
      N Offline
      nainakarri
      wrote on last edited by
      #2

      Hi I assume you want to print the variable value when executing in sqlserver studio management. If so, you can print the variable value by

      print variablename

      regards Naina

      Naina

      V 1 Reply Last reply
      0
      • N nainakarri

        Hi I assume you want to print the variable value when executing in sqlserver studio management. If so, you can print the variable value by

        print variablename

        regards Naina

        Naina

        V Offline
        V Offline
        vanikanc
        wrote on last edited by
        #3

        The printed value has to be a varchar or char. So, please cast the value to a varchar before printing.

        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