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. Web Development
  3. ASP.NET
  4. How to use sql UserDefined Funtion in Asp.Net

How to use sql UserDefined Funtion in Asp.Net

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-nethelptutorial
4 Posts 2 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.
  • S Offline
    S Offline
    Sneha Bisht
    wrote on last edited by
    #1

    Hi , m Create A UserDefined funtion in sqlserver 2000 , And Want to use this in Asp.net ; I use Stored Procedure 4 this by this code but...... CREATE PROCEDURE [dbo].[spShow_Total_Holiday_In_Current_Month] @day varchar(100) AS select **dbo.fnGetDatesforAday('10/01/2008','10/31/2008' , @day)**GO But this shows error "Invalid object name 'Attandance.dbo.fnGetDatesforAday' " tell me how can i solve this . Thanx

    R 1 Reply Last reply
    0
    • S Sneha Bisht

      Hi , m Create A UserDefined funtion in sqlserver 2000 , And Want to use this in Asp.net ; I use Stored Procedure 4 this by this code but...... CREATE PROCEDURE [dbo].[spShow_Total_Holiday_In_Current_Month] @day varchar(100) AS select **dbo.fnGetDatesforAday('10/01/2008','10/31/2008' , @day)**GO But this shows error "Invalid object name 'Attandance.dbo.fnGetDatesforAday' " tell me how can i solve this . Thanx

      R Offline
      R Offline
      Rajeshwary
      wrote on last edited by
      #2

      Hi i hope you don't have the function dbo.fnGetDatesforAday. so that u got the error. If u run the query manually in your DB server you will get the same error. "select dbo.fnGetDatesforAday('10/01/2008','10/31/2008' , @day) Go".

      R 1 Reply Last reply
      0
      • R Rajeshwary

        Hi i hope you don't have the function dbo.fnGetDatesforAday. so that u got the error. If u run the query manually in your DB server you will get the same error. "select dbo.fnGetDatesforAday('10/01/2008','10/31/2008' , @day) Go".

        R Offline
        R Offline
        Rajeshwary
        wrote on last edited by
        #3

        You will get the result if you create the below fuction in your DB server. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Description: To Get any weekday dates between two dates -- ============================================= CREATE FUNCTION fnGetDatesforAday ( -- Add the parameters for the function here @DtFrom DATETIME, @DtTo DATETIME, @DayName VARCHAR(12) ) RETURNS @DateList TABLE ([Day] varchar(20),Dt datetime) AS BEGIN IF NOT (@DayName = 'Monday' OR @DayName = 'Sunday' OR @DayName = 'Tuesday' OR @DayName = 'Wednesday' OR @DayName = 'Thursday' OR @DayName = 'Friday' OR @DayName = 'Saturday') BEGIN --Error Insert the error message and return INSERT INTO @DateList SELECT 'Invalid Day',NULL AS DAT RETURN END DECLARE @TotDays INT DECLARE @CNT INT SET @TotDays = DATEDIFF(DD,@DTFROM,@DTTO)-- [NO OF DAYS between two dates] SET @CNT = 0 WHILE @TotDays >= @CNT -- repeat for all days BEGIN -- Pick each single day and check for the day needed IF DATENAME(DW, (@DTTO - @CNT)) = @DAYNAME BEGIN INSERT INTO @DateList SELECT @DAYNAME,(@DTTO - @CNT) AS DAT END SET @CNT = @CNT + 1 END RETURN END GO

        S 1 Reply Last reply
        0
        • R Rajeshwary

          You will get the result if you create the below fuction in your DB server. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Description: To Get any weekday dates between two dates -- ============================================= CREATE FUNCTION fnGetDatesforAday ( -- Add the parameters for the function here @DtFrom DATETIME, @DtTo DATETIME, @DayName VARCHAR(12) ) RETURNS @DateList TABLE ([Day] varchar(20),Dt datetime) AS BEGIN IF NOT (@DayName = 'Monday' OR @DayName = 'Sunday' OR @DayName = 'Tuesday' OR @DayName = 'Wednesday' OR @DayName = 'Thursday' OR @DayName = 'Friday' OR @DayName = 'Saturday') BEGIN --Error Insert the error message and return INSERT INTO @DateList SELECT 'Invalid Day',NULL AS DAT RETURN END DECLARE @TotDays INT DECLARE @CNT INT SET @TotDays = DATEDIFF(DD,@DTFROM,@DTTO)-- [NO OF DAYS between two dates] SET @CNT = 0 WHILE @TotDays >= @CNT -- repeat for all days BEGIN -- Pick each single day and check for the day needed IF DATENAME(DW, (@DTTO - @CNT)) = @DAYNAME BEGIN INSERT INTO @DateList SELECT @DAYNAME,(@DTTO - @CNT) AS DAT END SET @CNT = @CNT + 1 END RETURN END GO

          S Offline
          S Offline
          Sneha Bisht
          wrote on last edited by
          #4

          Thanx . but i create the same Function it works fine , but when i call this function under stored Procedure then it show error .

          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