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. Clarification on SQL Server Function?

Clarification on SQL Server Function?

Scheduled Pinned Locked Moved Database
helpdatabasesql-serversysadminquestion
10 Posts 4 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.
  • H Offline
    H Offline
    H JJ
    wrote on last edited by
    #1

    Friends, Need one big help:) Getting error while creating function in SQL Server. Pls help to resolve the issue. FYI, the inputs as follows. - Function name: func_check_seat_availability Description: The function will check for the availability of seats in a particular bus on a given day. Input Parameters: in_bus_No, in_DateOfJourney, in_NoOfAdults, in_NoOfChildren. Return Values: Return 1 if the seats are available, else return 0. Table details: Column Data Type Constraints ----------------------------------------------------------- BookingId Varchar(4) P_Key, Starts with B100 ----------------------------------------------------------- BusNo Int (REFERENCES tbl_busdetails) ----------------------------------------------------------- CustomerId Int (REFERENCES tbl_Customer) ----------------------------------------------------------- DateOfBooking DateTime ----------------------------------------------------------- DateOfJourney DateTime DateOfJourney>=DateOfBooking ----------------------------------------------------------- NoOfAdults Int Greater than zero ----------------------------------------------------------- NoOfChildren Int Greater than or = to zero -----------------------------------------------------------

    L M U 3 Replies Last reply
    0
    • H H JJ

      Friends, Need one big help:) Getting error while creating function in SQL Server. Pls help to resolve the issue. FYI, the inputs as follows. - Function name: func_check_seat_availability Description: The function will check for the availability of seats in a particular bus on a given day. Input Parameters: in_bus_No, in_DateOfJourney, in_NoOfAdults, in_NoOfChildren. Return Values: Return 1 if the seats are available, else return 0. Table details: Column Data Type Constraints ----------------------------------------------------------- BookingId Varchar(4) P_Key, Starts with B100 ----------------------------------------------------------- BusNo Int (REFERENCES tbl_busdetails) ----------------------------------------------------------- CustomerId Int (REFERENCES tbl_Customer) ----------------------------------------------------------- DateOfBooking DateTime ----------------------------------------------------------- DateOfJourney DateTime DateOfJourney>=DateOfBooking ----------------------------------------------------------- NoOfAdults Int Greater than zero ----------------------------------------------------------- NoOfChildren Int Greater than or = to zero -----------------------------------------------------------

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      HARI JJ wrote:

      Getting error

      We have no way of knowing what the error is unless you let us know.

      H 2 Replies Last reply
      0
      • H H JJ

        Friends, Need one big help:) Getting error while creating function in SQL Server. Pls help to resolve the issue. FYI, the inputs as follows. - Function name: func_check_seat_availability Description: The function will check for the availability of seats in a particular bus on a given day. Input Parameters: in_bus_No, in_DateOfJourney, in_NoOfAdults, in_NoOfChildren. Return Values: Return 1 if the seats are available, else return 0. Table details: Column Data Type Constraints ----------------------------------------------------------- BookingId Varchar(4) P_Key, Starts with B100 ----------------------------------------------------------- BusNo Int (REFERENCES tbl_busdetails) ----------------------------------------------------------- CustomerId Int (REFERENCES tbl_Customer) ----------------------------------------------------------- DateOfBooking DateTime ----------------------------------------------------------- DateOfJourney DateTime DateOfJourney>=DateOfBooking ----------------------------------------------------------- NoOfAdults Int Greater than zero ----------------------------------------------------------- NoOfChildren Int Greater than or = to zero -----------------------------------------------------------

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        What precisely are you expecting us to do with this information? You need to supply the script for the function and the error you are getting for us to help you!

        Never underestimate the power of human stupidity RAH

        H 1 Reply Last reply
        0
        • L Lost User

          HARI JJ wrote:

          Getting error

          We have no way of knowing what the error is unless you let us know.

          H Offline
          H Offline
          H JJ
          wrote on last edited by
          #4

          Could you send me the function queries. Iam new to this database, struggling hard to get into the basics too. having lot of doubts.

          1 Reply Last reply
          0
          • L Lost User

            HARI JJ wrote:

            Getting error

            We have no way of knowing what the error is unless you let us know.

            H Offline
            H Offline
            H JJ
            wrote on last edited by
            #5

            Hi Shameel, Thanks for your mail. Could you send me the function queries. Iam new to this database, struggling hard to get into the basics too. having lot of doubts.

            L 1 Reply Last reply
            0
            • M Mycroft Holmes

              What precisely are you expecting us to do with this information? You need to supply the script for the function and the error you are getting for us to help you!

              Never underestimate the power of human stupidity RAH

              H Offline
              H Offline
              H JJ
              wrote on last edited by
              #6

              Could you send me the function queries. Iam new to this database, struggling hard to get into the basics too. having lot of doubts.

              M 1 Reply Last reply
              0
              • H H JJ

                Hi Shameel, Thanks for your mail. Could you send me the function queries. Iam new to this database, struggling hard to get into the basics too. having lot of doubts.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                What have you tried? What is the error that you get? If you expect someone to write the function for you, then you're in the wrong place.

                H 1 Reply Last reply
                0
                • L Lost User

                  What have you tried? What is the error that you get? If you expect someone to write the function for you, then you're in the wrong place.

                  H Offline
                  H Offline
                  H JJ
                  wrote on last edited by
                  #8

                  Sorry Shammel. Its very important for me, thatsy expecting help. Pls let me help how to resolve the queries. I tried the following. CREATE FUNCTION func_check_seat_availability ( @in_bUS_No int, @in_DateOfJourney datetime, @in_NoOfAdults int, @in_NoOfChildren int ) RETURNS decimal(36,30) AS BEGIN --considering 64 is the total count of bus select case when sum(NoOfAdults+NoOfChildren+@in_NoOfAdults+@in_NoOfChildren) >= 64 then 0 when sum(NoOfAdults+NoOfChildren+@in_NoOfAdults+@in_NoOfChildren) < 64 then 1 End from Bus_Details where BusNo=@in_bus_No and DateOfJourney=@in_DateOfJourney END

                  1 Reply Last reply
                  0
                  • H H JJ

                    Friends, Need one big help:) Getting error while creating function in SQL Server. Pls help to resolve the issue. FYI, the inputs as follows. - Function name: func_check_seat_availability Description: The function will check for the availability of seats in a particular bus on a given day. Input Parameters: in_bus_No, in_DateOfJourney, in_NoOfAdults, in_NoOfChildren. Return Values: Return 1 if the seats are available, else return 0. Table details: Column Data Type Constraints ----------------------------------------------------------- BookingId Varchar(4) P_Key, Starts with B100 ----------------------------------------------------------- BusNo Int (REFERENCES tbl_busdetails) ----------------------------------------------------------- CustomerId Int (REFERENCES tbl_Customer) ----------------------------------------------------------- DateOfBooking DateTime ----------------------------------------------------------- DateOfJourney DateTime DateOfJourney>=DateOfBooking ----------------------------------------------------------- NoOfAdults Int Greater than zero ----------------------------------------------------------- NoOfChildren Int Greater than or = to zero -----------------------------------------------------------

                    U Offline
                    U Offline
                    uspatel
                    wrote on last edited by
                    #9

                    try something like

                    CREATE FUNCTION func_check_seat_availability
                    (
                    @in_bUS_No int,
                    @in_DateOfJourney datetime,
                    @in_NoOfAdults int,
                    @in_NoOfChildren int
                    )
                    RETURNS decimal(36,30)
                    AS
                    BEGIN
                    --considering 64 is the total count of bus
                    declare @value decimal(36,30)
                    select
                    @value=case when sum(@in_NoOfAdults+@in_NoOfChildren) >= 34 then 0
                    when sum(@in_NoOfAdults+@in_NoOfChildren) < 14 then 1
                    end
                    from Details where BusNo=@in_bus_No and DateOfJourney=@in_DateOfJourney
                    return @value
                    END

                    Thanks


                    Blog |Articles|Answers

                    1 Reply Last reply
                    0
                    • H H JJ

                      Could you send me the function queries. Iam new to this database, struggling hard to get into the basics too. having lot of doubts.

                      M Offline
                      M Offline
                      Mycroft Holmes
                      wrote on last edited by
                      #10

                      What I have nothing better to do than write your code for you tsk tsk not going to happen I'm afraid. How can you expect to learn if you don't research and try and do the coding, getting help when you stumble.

                      Never underestimate the power of human stupidity RAH

                      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