Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008
    Posts
    7

    Unanswered: Trying to create SQL function from VB.Net Windows App

    I'm trying to create a function from a VB.Net windows application.

    I can create a simple function no problem, but I keep getting an error when I try to execute the following code:

    The error is : Line 1: Incorrect syntax near ')'.

    Any help would be appreciated!



    Sql = "CREATE FUNCTION dbo.ftmFixTime (@InputString varchar(20))"
    Sql += " RETURNS VARCHAR(20)"
    Sql += " AS"
    Sql += " BEGIN()"
    Sql += " Declare @WorkString as Varchar(6)"
    Sql += " Declare @WorkHour as char(2)"
    Sql += " Declare @WorkMinute as Char(2)"
    Sql += " Declare @WorkSecond as Char(2)"
    Sql += " DECLARE @FixedTime VARCHAR(20)"
    Sql += " set @WorkString = @InputString"
    Sql += " if len(@WorkString) < 6 Begin set @WorkString = '0' + @WorkString end"
    Sql += " set @WorkHour = Substring(@WorkString,1,2)"
    Sql += " set @WorkMinute = Substring(@WorkString,3,2)"
    Sql += " set @WorkSecond = Substring(@WorkString,5,2)"
    Sql += " if Convert(int,@WorkHour) > 23 begin set @WorkHour = '00' end"
    Sql += " if Convert(int,@WorkMinute) > 59 begin set @WorkHour = '00' end"
    Sql += " if Convert(int,@WorkSecond) > 59 begin set @WorkSecond = '00' end"
    Sql += " set @FixedTime = @WorkHour + ':' + @WorkMinute + ':' + @WorkSecond"
    Sql += " RETURN (@FixedTime)"
    Sql += " End"


    FalconConn.Open()
    SqlCmd = New SqlClient.SqlCommand(Sql, FalconConn)
    SqlCmd.CommandText = Sql
    SqlCmd.ExecuteNonQuery()
    FalconConn.Close()

  2. #2
    Join Date
    Aug 2008
    Posts
    7
    this has been answered, I needed to remove the braces after Begin()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •