Create A TO_DATE Function For Use In SQLServer 2005
Feb 28, 2008
Hi ,
I 'm working with visual studio 2005 and I have created an SQLServer Project.
I'm using the CLR functionality which comes with SQLserver 2005. This means that I can write VB.nEt code and use it inside Sqlserver 2005.So far so good.
I am now inside the .NET
I have created a Function(must remind you that I have created an SQLserver Project) which takes two string arguments. The date value in a string format and the string format.
In Our case the function returns a string.It will return a datetime although.
So we have
Dim Datetime_Val As DateTime = Nothing
Dim Date_Val As Date = Nothing
Dim StrTemp As String = ""
Dim StrDateTemp As String = Nothing
Dim StrTimeTemp As String = Nothing
Dim ls_return As String = Nothing
Dim lindexof As Integer
Dim Counter As Integer = 0
lindexof = 0
Select Case StrFormat
Case "DD-MM-YYYY HH24:MIS"
For Counter = 1 To 2
lindexof = StrDate.IndexOf("-", lindexof + 1)
Next
lindexof += 5
StrDateTemp = StrDate.Substring(0, lindexof).Trim
StrTimeTemp = StrDate.Substring(StrDateTemp.Length, StrDate.Length - StrDateTemp.Length).Trim
ls_return = StrDateTemp & " " & StrTimeTemp
End Select
The above is a simple code. As you can see I'm trying to convert the TO_DATE function ,which work with ORACLE, to make it work with SQLServer 2005.
I've been trying unsuccessfully to combine the variables StrDateTemp and StrTimeTemp into a datetime value. I used the following code but nothing
Datetime_Val = CDate(StrDateTemp & " " & StrTimeTemp)
Didn't work
Datetime_Val = Convert.ToDateTime(StrDateTemp & " " & StrTimeTemp)
Didn't work
Datetime_Val = DateTime.Parse(StrDateTemp & " " & StrTimeTemp)
Didn't work
Inside SQlServer I used this SQL statement
Select dbo.TO_DATE('31-12-1990 00:26:46','DD-MM-YYYY HH24:MIS')
But I am receiveing an error. I want to avoid changing all of my applications with a specific format.This sql statement without the dbo prefix I'm using in Oracle. I want to keep the format of the SQL and let VB.NET do the parsing for me. It is easier for me to put in my SQLs the dbo infront rather changing the complete SQL.
I have two questions . How am I going to create a TO_DATE function which Oracle uses and write something similar in SQLserver ?
And If I cannot do that how am I going to get the database 's datetime format and create with VB.NET the Datetime value from the two variables ?
My problem I believe is quite complex. I would be mostly appreciated if you could help me on this.
Thank you
View 8 Replies
ADVERTISEMENT
Jul 14, 2006
I have installed sqlserver 2005 and by mistake i have made a default instance. I previously had sqlserver 2000 installed on my machine. Now I want to create a new instance of sqlserver 2005 but dont know how to do it .... Please help me on this
View 1 Replies
View Related
Feb 22, 2006
Hi,
Apologies if this has been asked before, i've done a search but can't find a definitive answer.
I've created a table in an SQLExpress 2005 db using Server Managment Studio Express.
My intention is to use GUID fields as surrogate PK's. I therefore wanted to add a additional index to prevent duplicate records being added to the table. Not having used SQLServer before could someone confirm or deny that this is the correct way to do this. The PK field [EPISODEID{unique identifier}] is set as a non-clustered index. And i've created a second clustered index using the two fields that create a unique record. I've added a screen shot if that is any help.
Thanks
Chris
View 2 Replies
View Related
May 10, 2007
We have a static class that makes an HTTPWebRequest to get XML data from one of our vendors. We use this as input to a stored proc in SQLServer2005. When I compile this class and call it from a console application in visual studio it executes in milliseconds, everytime. When I compile it, create the assembly and clr function and execute it in SQLServer, it takes around 14 seconds to execute the first time, then on subsequent requests it is again really fast, until I wait for 10 seconds and re-execute, once again it is slow the first time and then fast on subsequent requests. We do not see this behavior when executing outside SQLServer. Makes me think that some sort of authentication is perhaps taking place the first time the function is run in SQLServer? I have no idea how to debug this further. Anyone seen this before or have any ideas?
Here is the class:
Code Snippet
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace Predict.Services
{
public static class Foo
{
public static string GetIntradayQuote(string symbol)
{
string returnQuote = "";
HttpWebRequest request = (HttpWebRequest)(WebRequest.Create("http://data.predict.com/predictws/detailed_quote.html?syms=" + symbol + "&fields=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,28,30"));
request.Timeout = 1000;
HttpWebResponse response = (HttpWebResponse)(request.GetResponse());
StreamReader streamReader = new StreamReader(response.GetResponseStream());
returnQuote = streamReader.ReadToEnd();
streamReader.Close();
response.Close();
return returnQuote;
}
}
}
When I run call it from a console app it is fine.
I compile it into a dll and then create the assembly and function as follows:
Code Snippet
drop function fnTestGetIntradayQuoteXML_SJS
go
drop assembly TestGetIntradayQuoteXML_SJS
go
create ASSEMBLY TestGetIntradayQuoteXML_SJS from 'c:DataBackupsCLRLibrariesTestGetIntradayQuote_SJS.dll' WITH PERMISSION_SET = EXTERNAL_ACCESS
go
CREATE FUNCTION fnTestGetIntradayQuoteXML_SJS(@SymbolList nvarchar(max)) RETURNS nvarchar(max) AS EXTERNAL NAME TestGetIntradayQuoteXML_SJS.[Predict.Services.Foo].GetIntraDayQuote
go
declare @testing nvarchar(max)
set @testing = dbo.fnTestGetIntradayQuoteXML_SJS('goog')
print @testing
When I execute the function as above, again, really slow the first time, then fast on subsequent calls. Could there be something wrong with the code, or some headers that need to be set differently to operate from the CLR in SQLServer?
Regards,
Skipper.
View 1 Replies
View Related
Apr 22, 2008
Can anyone help me to create a URL decode user defined function in SQL Server 2005?
I want to use the method [System.Web.HttpUtility.UrlDecode] in .net framework, and I try to add it as a CLR function to SQL Server but always fail. It depends on [System.Web.dll], and when I try to create assembly [System.Web] using following scripts, it will fail:
CREATE ASSEMBLY [System.Web] FROM 'C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Web.dll'
WITH PERMISSION_SET = UNSAFE
Error:
CREATE ASSEMBLY for assembly 'System.Web' failed because assembly 'System.Web' is not authorized for PERMISSION_SET = UNSAFE.
The assembly is authorized when either of the following is true:
the database owner (DBO) has UNSAFE ASSEMBLY permission and the database has the TRUSTWORTHY database property on;
or the assembly is signed with a certificate or an asymmetric key that has a corresponding login with UNSAFE ASSEMBLY permission.
If you have restored or attached this database, make sure the database owner is mapped to the correct login on this server. If not, use sp_changedbowner to fix the problem.
I have searched the MSDN and then add following scripts before mine:
ALTER DATABASE [DatabaseName] SET TRUSTWORTHY ON
CREATE ASYMMETRIC KEY SystemWebKey FROM EXECUTABLE FILE = 'C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Web.dll'
CREATE LOGIN CLRLogin FROM ASYMMETRIC KEY SystemWebKey
GRANT UNSAFE ASSEMBLY TO CLRLogin
But unfortunately it fails again with same error.
View 5 Replies
View Related
Aug 21, 2007
Hiiiiiiii all
I have to make a user defined function in c# as the class liberary and create a dll file, now i want to use this function in SQL Server 2005 as a part of CLR Integration
I have tried like this
CREATE ASSEMBLY abc
FROM 'C:abc.dll'
WITH PERMISSION_SET = SAFE
but it gives me
incorrect syntax error
so plzzzzz anyone help me wht to do in my probbbbbbbbb???????
Pratik Kansara
View 13 Replies
View Related
Apr 24, 2007
Hi,
I am looking for tutorials about how to create dts et dtsx files.
Thanks for your help.
Arioule.
View 1 Replies
View Related
Apr 8, 2006
Ok i'm trying to figure out how to properlyuse the to_date function. Ive read about it in my book and tried looking up some examples of it online... but im still confused on how to use it in my situation.
SELECT TITLE,INITCAP(PUBDATE(TO_DATE(PUBDATE,'Month DD, YYYY'))) FROM BOOKS;
That was my last attempt. Im just trying to get the title and the date for all of the books in the books table. the first letter of the book is supposed tobe capitalized, so i used initcap but then im supposed to put them month in Month DD, YYYY format. I looked it up, seems To_date is my answer but all of the examples seem to confused me. They are all being used along with where functions and I think its confusing me. Can anyone help explain how to use it in this situation?
View 5 Replies
View Related
May 2, 2008
Hello,
I am very new to SQL and was handed some Oracle code to put into a SQL Server 2005 db. A few errors come up, but the one I'm having the hardest time converting is:
INSERT INTO Reservations VALUES (102, TO_DATE('10/14/03', 'MM/DD/YY'),
22, TO_DATE('10/10/03', 'MM/DD/YY'));
and the error message that accompanies it upon parsing is:
Msg 195, Level 15, State 10, Line 86
'TO_DATE' is not a recognized built-in function name.
Any help converting this to SQL Server's liking would be greatly appreciated.
Thanks!
Fry
View 3 Replies
View Related
Jan 30, 2008
Hi All:
We have a database date column in this format: 1/27/2008 1:20:00 AM and need a date or time function to cast local JVM time into the above format.
Suggest me the best options.
1. To go for a more comfortable date format in the database itself or
2. To have an appropriate conversion in my code.( I am not feeling good about the suffix AM/PM in the date column!)
Thanks.
View 20 Replies
View Related
Sep 20, 2006
Hi experts;
I have a problem with unicode character 0x2300
I created this table
create table testunicode (Bez nchar(128))
Insert Data
insert into testunicode (Bez)values('Œ€„¢')
with 2 Unicode characters
Œ€ = 0x2300
„¢ = 0x2122
Selecting the data
select Bez from testunicode
I see
"?„¢"
„¢ = 0x2122 is ok but instead of 0x2300 there is 0x3f
When I modify the insert statement like that ( 8960 = 0x2300 )
insert into testunicode (Bez)values(NCHAR(8960)+'„¢')
and select again voila i see
"Œ€„¢"
Does anyone have an idea?
Thanks
View 1 Replies
View Related
Apr 18, 2008
I am trying to 'load' a copy of a SQLServer 2000 database to SQLServer 2005 Express (on another host). The copy was provided by someone else - it came to me as a MDF file only, no LDF file.
I have tried to Attach the database and it fails with a failure to load the LDF. Is there any way to bypass this issue without the LDF or do I have to have that?
The provider of the database says I can create a new database and just point to the MDF as the data source but I can't seem to find a way to do that? I am using SQL Server Management Studio Express.
Thanks!!
View 1 Replies
View Related
Jun 14, 2006
I have an app that uses a sqlserver 2000 jdbc driver to connect to a sqlserver 2000.
Is it possible to do a direct replacement of sqlserver 2000 with sqlserver 2005 express just by reconfiguring the app to point to the express? The app would still be using the sqlserver 2000 jdbc driver to try and make the connection.
If that is a possibility, what can be some differences in the configuration? Previously with 2000 the config information I entered is:
server name: "machinename"( or ip). I've also tried "machiname/SQLEXPRESS"
DB name: name of db instance
port: 1433(default)
user and pass.
My attempts so far results in
"java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket."
and
"java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL."
View 1 Replies
View Related
Feb 9, 2006
Hello,
I have an SQLServer Mobile database, and I would like to know if there is a way to upgrade it to SQLServer 2005 (.mdf) database. My database has no records in it, just the structure (tables etc). What I am actually asking is if I can create automatically a new SQLServer 2005 Database with the same structure as my existin SQLSErver Mobile database
Thanks in advance,
TassosTS
View 1 Replies
View Related
Jun 20, 2007
Hello people.
I am in the process of planning a server upgrade to sql2005 x64.
I created 2 linked servers: one to a SQL2000 sp4 server and one to a SQL7.0 SP3.
I have the following error when I query the linked servers.
OLE DB provider "SQLNCLI" for linked server "IVDM2K" returned message "Unspecified error".
OLE DB provider "SQLNCLI" for linked server "IVDM2K" returned message "The stored procedure required to complete this operation could not be found on the server. Please contact your system administrator.".
Msg 7311, Level 16, State 2, Line 1
Cannot obtain the schema rowset "DBSCHEMA_TABLES_INFO" for OLE DB provider "SQLNCLI" for linked server "IVDM2K". The provider supports the interface, but returns a failure code when it is used.
I am aware of KB 906954.
http://support.microsoft.com/default.aspx?scid=kb;en-us;906954
I applied the instcat.sql on the SQL2000SP4 server and my linked server issues for that one are gone.
However, I ran the instcat.sql script on the SQL7.0 sp3 server and the linked server is still giving me an issue.
Can someone help me find a solution to this?
View 1 Replies
View Related
Sep 25, 2000
Hi
My question is about the INSTR function of MSAccess
I want to know
Goodbye at every
I would you like to know if in TransactSQL of SQLServer7 exist a function that return the position of a string into an other string .
that is a Instr function MSAccess like
INSTR([Start,]expression1,expression2[,Comparison])
I'm sorry for my bad English
Thank you for everything
Emiliano
View 2 Replies
View Related
Mar 1, 2005
I had built a one calander in SQLSERVER
View 1 Replies
View Related
Jun 16, 2008
Hi I need a function which gets 3 parameters and input and returns 4 integers as output.
I don't know how to return 4 integers as output
any idea is appreciated.
View 7 Replies
View Related
Apr 3, 2007
Hi,
I am trying to create a inline function which is listed below.
USE [Northwind]
SET ANSI_NULLS ON
GO
CREATE FUNCTION newIdentity()
RETURNS TABLE
AS
RETURN
(SELECT ident_current('orders'))
GO
while executing this function in sql server 2005 my get this error
CREATE FUNCTION failed because a column name is not specified for column 1.
Pleae help me to fix this error
thanks
Purnima
View 3 Replies
View Related
May 24, 2007
i have a quite strange condition...when i add some value in database with getdate() function it only returns date and minute not the seconds...does somebody have an experience about this
View 3 Replies
View Related
Jul 23, 2005
I use a database that has user names stored in Encrypted format usingthe following API.Declare Sub Encrypt2 Lib "QPRO32.DLL" (ByVal Work As String, ByValPASSWORD As String)Every time i require the user name i have to again decrypt the nameusing the same function.My problem is that when i fetch a large number of records i have toloop through every record and call the encrypt function for eachrecord.Instead of binding the recordset to my control i need to loopthrough and fill my controlA MSHFlexGrid in Vb6.0.Is there a way out to this problem that will make my record populatiogfaster withoutout changing the current Encrypted users.Thanx in Advance
View 2 Replies
View Related
May 9, 2006
Hi every body,
I have SQLServer 2005 runs well for months and stop working after install SqlServer2005 SP1. I try to reinstall the SQLServer 2005 but I have problem when install work station component on my and the error is "There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor". Please help me to fix this bug. I do not want to reformat my machine.
John Dang
View 1 Replies
View Related
Apr 5, 2006
I wanted to programmatically create SqlServer JobSchedule
The job is to copy data from a particular table in one Database to another table in another DataBaseUser should be able to Schedule/modify Date and Time on which a job is to be executed is to be configured through a UI Screen (WebForm.aspx)
I am using VSStudion2003 ,ASP.net with VB.net with SQL2000 as database .
ANY idea on how to do this ?????
Please help me?
Thank u all in advance
View 1 Replies
View Related
Jul 23, 2005
I am running SQLServer 2000 SP3 with MDAC 2.8.On instances created via MSDE, I am unable to create the first step ina job. Instances created with SQLServer 2000, this problem does notoccur.The message I am receiving on the instances created with MSDE, themessage I get immediately upon pressing the Add button to define a stepis "Error 170: Line 1: Incorrect syntax near ''"Any help would would be greatly appreciated.Wardell Castles
View 4 Replies
View Related
May 9, 2005
hi
i am using database sqlserver,i am searching for varray concept like in oracle to store multiple values in a single column(as array column) like that shell i do in sql server
1.how to create array column in a table using sqlserver
if possible how can i use select query for that
View 4 Replies
View Related
Mar 6, 2008
I'm installing Windows Small Business Server 2003 R2 Premium. I am at the stage where I am installing the Premium Technologies. Specifically, I am trying to configure permissions for the new SHAREPOINT instance of SQL Server 2005. When I try to create the new login NT AuthorityNetwork Service, typing it exactly as specified in the instructions, I get the following error:
Create failed for Login 'NT AUTHORITYNetwork Service' (Microsoft.Sqlserver.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+Login&LinkId=20476
------------------------------
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
Windows NT user or group 'NT AUTHORITYNetwork Service' not found. Check the name again. (Microsoft SQL Server, Error: 15401)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.1399&EvtSrc=MSSQLServer&EvtID=15401&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------
The following links yielded nothing:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.1399&EvtSrc=MSSQLServer&EvtID=15401&LinkId=20476
Does anyone know what's causing this? I've done a few installs of SBS R2 Premium and this is the first time I encountered this.
View 1 Replies
View Related
Mar 21, 2006
Hello!How can I make this function in MS SQL:CREATE FUNCTION id_name() RETURNS INTEGER AS 'SELECT MAX(ID)+1 FROM Test;'Thanks!
View 2 Replies
View Related
Mar 15, 2008
I have the following function that I was able to put together with the help of the following article http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/rowset-string-concatenation-which-method-is-best.aspx but I'm having some problems with it any help would be greatly appreciated.
USE database1
GO
CREATE FUNCTION dbo.Concatdwg_Seq (@prt_Mark CHAR(2))
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @Output VARCHAR(8000)
SET @Output = ''
SELECT @Output =CASE @Output
WHEN '' THEN dwg_Seq
ELSE @Output + ', ' + dwg_Seq
END
FROM dbo.Un_Combined
WHERE prt_Mark = @prt_Mark
ORDER BY dwg_Seq
RETURN @Output
END
GO
prt_Mark | dwg_Seq
12 | 12a,23b
25c | 1b,5e,8d,100as
I get the following errors
Msg 325, Level 15, State 1, Line 2
Incorrect syntax near 'FUNCTION'. You may need to set the compatibility level of the current database to a higher value to enable this feature. See help for the stored procedure sp_dbcmptlevel.
Msg 137, Level 15, State 2, Line 14
Must declare the scalar variable "@prt_Mark".
Msg 178, Level 15, State 1, Line 17
A RETURN statement with a return value cannot be used in this context.
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'To'.
View 5 Replies
View Related
May 25, 2007
I currently have SQL Server Management Studio Express 2005 and would like to upgrade my machine to SQL Developer 2005 as easily as possible. Keeping my databases and such.
Any recommendations on the best way to do this would be greatly appreciated.
thanks!
View 3 Replies
View Related
Aug 20, 2006
Hello
Im pretty new to development so..... be nice guys.
I have VS2005 pro and SQL Server 2005 developer edition installed. When I open VS, in the server explorer i can connet to databases located on the SQL directory (SQL Server runs perfectly) But when i try to add an sql server to my project( add new item --> SQL database) it gives me an error saying "Connection to SQL server files (*.mdf) require SQL Server Express 2005 to function properly. Please verify the installation of the component......"
HELP! donno what VS wants!
View 1 Replies
View Related
Jul 26, 2007
I want to divide day of month as
example: month is July
week1: 02-07
week2: 09-14
week3: 16-21
week4: 23-28
week5: 30-31
--========Sunday is not including
example: month is August:
week1: 01-04
week2: 06-11
week3: 13-18
week4: 20-25
week5: 27-31
but if December:week1: 01
week2: 03-08
week3: 10-15
week4: 17-22
week5: 24-29week6:31 please help me!thanks so much!
View 1 Replies
View Related
Aug 5, 2002
how do create function in sql server 7.0
View 1 Replies
View Related
Mar 28, 2002
Hi All,
I'm running SQL Server 2002 and trying to create a User Defined Function. However, everytime I try to save the script I get Error 170 Incorrect Syntax near 'FUNCTION'.
This happens if I create the Function from Code or use the Enterprise Manager. I'm logged in with 'sa' privs, so I don't think it's a privilege issue. I'm well confused.
Anyone help?
TIA
William.
View 1 Replies
View Related