Can I Do Regular Expressions Using TSQL In SQL Server2005?
Apr 20, 2007
I am running PHP with SQL Server 2005. I have [bold] in some of the values in my result set, which needs to be striped out. I had a function in SQL Server2000 that did that, but the same function does not work in SQL Server2005. Any dieas?
CREATE FUNCTION
dbo.fn_regex(@pattern varchar(255), @matchstring varchar(8000))
RETURNS int
AS
BEGIN
declare @obj int
declare @res int
declare @match bit
set @match=0
exec @res=sp_OACreate 'VBScript.RegExp',@obj OUT
IF (@res <> 0) BEGIN
RETURN NULL
END
exec @res=sp_OASetProperty @obj, 'Pattern', @pattern
IF (@res <> 0) BEGIN
RETURN NULL
END
exec @res=sp_OASetProperty @obj, 'IgnoreCase', 1
IF (@res <> 0) BEGIN
RETURN NULL
END
exec @res=sp_OAMethod @obj, 'Test',@match OUT, @matchstring
IF (@res <> 0) BEGIN
RETURN NULL
END
exec @res=sp_OADestroy @obj
return @match
END
GO
View 7 Replies
ADVERTISEMENT
Jun 24, 2008
Hi, the Microsoft SQL Server version is 2000
Basically I want use a basic regular expression but can't seem to get the syntax right.
i want to compare ID_short = ID_Long
ID_short is a truncated version of ID_Long, and I want to search on the beginning only (hence I can't use the 'LIKE' comparative on it's own).
What is the syntax to use Reg Expressions (or if anyone knows a non RegExp way of searching the beginning please let me know).
Thanks
View 5 Replies
View Related
Feb 9, 2007
Hi,
I have a crappy old database that has an email field with a lot of bad data, and I need to use SSIS to extract a list of names & email addresses.
I have an OLE DB Source set up to pull the relevant columns out of the database. Is there a way that I could setup a Regular Expression based filter to disregard any rows where my email Regex does not match the value of the email column?
Thanks,
John
View 4 Replies
View Related
Sep 27, 2007
Hi everyone,
Is it possible? I haven't idea how to implement as if it were done from conventional .Net code
I'd like to check every field for a plan file
First field NNNNNNN
Second field XXXNNNNNNN
,,
Thanks for any input or idea,
View 11 Replies
View Related
Sep 24, 2006
Hi all,
i wrote a little function that is basically supposed to give me a match of a regular expression in C#. i tested it out in VS05 and it seems to work fine. It hits the fan when i try it on SQL Query analyzer once deployed. Anyone have any idea why?
here is the C# class that I deploy to a db using VS05.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Text.RegularExpressions;
public partial class RegExTest
{
[Microsoft.SqlServer.Server.SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static string RegExMatch(string pattern, string matchString)
{
Regex r1 = new Regex(pattern);
if (r1.Match(matchString.TrimEnd(null)).Success)
{
Regex testReg = new Regex(pattern);
Match regMatch = testReg.Match(matchString);
string runnumber = regMatch.ToString().TrimEnd('_');
runnumber = runnumber.TrimStart('_');
return runnumber;
}
else
{
return null;
}
}
};
Basically i have a teststring that looks like abc_xxx_nnndef. xxx and nn are both numbers, and im using the pattern _\d{3}_ to test it out in SQL (i need the numbers between '_' and '_'). But it never even proceeds past the if statement in SQL i think. here is the basic SQL that i use to test the above function:
use northwind
go
declare @teststring varchar(50),
@pattern varchar(10),
@out varchar(50)
set @teststring = 'dw_012_34.ext'
set @pattern = '_\d{3}_'
set @out = dbo.RegExMatch(@pattern, @teststring )
select @teststring
select @pattern
select @out
Anyone have any suggestions as to why it works in VS 05 when I use it in a C# program, but fails on the SQL version?
View 8 Replies
View Related
Apr 27, 2007
HiI have a large table with allot of data in it, Im trying to find the correct SQL statement to select all the records that do not start with a letter or a number.So some records may start with a '~' and a few '$' and even some '?'. So I would like a statement that would select all of these while leaving out any records that start with anything else, such as numbers or letters.And on a similar theme, Im also trying to select all records that start with a number. Ive been using the "select blah from blah where LIKE 'a%'" for each letter and ive tried to have a play and search around that statement....
Today I was told to use a regex within my 'SELECT' statement, but I had never heard of this being done before... so I done a number of searches on Google and although I found references, I didnt actually find any examples. So when I tried to put something together I kept getting errors.
Ive used regular expressions before so theres no problem writing the expression that I need, however Ive no idea how to implement it into a SELECT statement.
If someone could please show me an example of the structure/syntax of an sql select query that contains a regex then I would be most appreciative! :)
View 2 Replies
View Related
Jul 20, 2005
Is it possible to use the REPLACE function in SQL Server 2000 so thatit returns a string containing only alpha-numeric characters (muchlike using regular expressions)?Thank you in advance for any suggestion.Darren.
View 1 Replies
View Related
Oct 30, 2006
How can I use regular expressions in WHERE clause directly?
select * from mytbl where myfld like '[0-9]*key'
View 3 Replies
View Related
Mar 31, 2006
Hi-
Someone posted on a thread that you can use VB (or C#) to write Regular Expressions for SQL Server 2005. I know how to write RegEx in VB, so can someone point me to a reference which explains how to use them in / with SQL2005? Or, can someone explain how?
Thanks,
-David
View 4 Replies
View Related
Feb 11, 2008
Hello forum, I need extract a substring form a string that follows a regular expressions -->
T:1º/PQ:1/TALLA:2(MOD.51 100/150)
T:<number>º/PQ:<number>...
I need to extract only the numbers. The SUBSTRING functions is insuficient for me, because in some cases de number can be 1, 10, 100, 1000, ...
I would like me use it as:
SELECT RegularExpression (Field)
Can you help me, please.
Thanks for all in advanced. I will appreciate a lot your help.
View 3 Replies
View Related
Mar 23, 2006
Hi,I trying to write a select statement that will return each of my salesmen a region code based on a table of post codes using wildcards... eg.MK1 1AA would be matched in the region code table to MK1%SELECT dn.DEALER_CODE, dn.NAME AS DNAME, rc.REGION_ID,rc.POST_CODE, dn.POSTAL_CODEFROM REGIONAL_CODES rc CROSS JOINDEALER_NAW dnWHERE (dn.POSTAL_CODE LIKE rc.POST_CODE)The above statement works BUT there are some post code areas such asour friends in Milton Keynes that are split into two regions... eg MK1is region id 2 and MK10 is region 3.So a dealer with post code MK10 1AA would be matched to both rowsreturning duplicatesPOST_CODE REGION_IDMK1% 2MK10% 3I think the answer would lie in a subquery which returns the ID of theregion with the longest length of the postcode match (e.g.len(POST_CODE) for the rc table... return only the MAX....any ideas????Any help muchos appreciated, and I apologies now for the naming of thedealers name as a reserve word... not me!Ct
View 2 Replies
View Related
Dec 11, 2007
I want to have this query insert a bunch of XML but i get this error...
Msg 128, Level 15, State 1, Procedure InsertTimeCard, Line 117
The name "ExpenseRptID" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
Msg 128, Level 15, State 1, Procedure InsertTimeCard, Line 151
The name "DateWorked" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
What am i doing wrong...Can anyone help me out!! Thanks!!
p.s I know this query looks crazy...
Code Block
IF EXISTS (SELECT NAME FROM sysobjects WHERE NAME = 'InsertTimeCard' AND type = 'P' AND uid=(Select uid from sysusers where name=current_user))
BEGIN
DROP PROCEDURE InsertTimeCard
END
go
/*********************************************************************************************************
** PROC NAME : InsertTimeCardHoursWorked
**
** AUTHOR : Demetrius Powers
**
** TODO/ISSUES
** ------------------------------------------------------------------------------------
**
**
** MODIFICATIONS
** ------------------------------------------------------------------------------------
** Name Date Comment
** ------------------------------------------------------------------------------------
** Powers 12/11/2007 -Initial Creation
*********************************************************************************************************/
CREATE PROCEDURE InsertTimeCard
@DateCreated DateTime,
@EmployeeID int,
@DateEntered DateTime,
@SerializedXML text,
@Result int output
as
declare @NewTimeCardID int
select @NewTimeCardID = max(TimeCardID) from OPS_TimeCards
-- proc settings
SET NOCOUNT ON
-- local variables
DECLARE @intDoc int
DECLARE @bolOpen bit
SET @bolOpen = 0
--Prepare the XML document to be loaded
EXEC sp_xml_preparedocument @intDoc OUTPUT, @SerializedXML
-- check for error
IF @@ERROR <> 0
GOTO ErrorHandler
--The document was prepared so set the boolean indicator so we know to close it if an error occurs.
SET @bolOpen = 1
--Create temp variable to store values inthe XML document
DECLARE @tempXMLTimeCardExpense TABLE
(
TimeCardExpenseID int not null identity(1,1),
TimeCardID int,
ExpenseRptID int,
ExpenseDate datetime,
ProjectID int,
ExpenseDescription nvarchar(510),
ExpenseAmount money,
ExpenseCodeID int,
AttachedRct bit,
SubmittoExpRep bit
)
DECLARE @tempXMLTimeCardWorked TABLE
(
TimeCardDetailID int not null identity(1,1),
TimeCardID int,
DateWorked DateTime,
ProjectID int,
WorkDescription nvarchar(510),
BillableHours float,
BillingRate money,
WorkCodeID int,
Location nvarchar(50)
)
-- begin trans
BEGIN TRANSACTION
insert OPS_TimeCards(NewTimeCardID, DateCreated, EmployeeID, DateEntered, Paid)
values (@NewTimeCardID, @DateCreated, @EmployeeID, @DateEntered, 0)
-- check for error
IF @@ERROR <> 0
GOTO ErrorHandler
--Now use @intDoc with XPATH style queries on the XML
INSERT @tempXMLTimeCardExpense (TimeCardID, ExpenseRptID, ExpenseDate, ProjectID, ExpenseDescription, ExpenseAmount, ExpenseCodeID, AttachedRct, SubmittoExpRep)
SELECT @NewTimeCardID, ExpenseRptID, ExpenseDate, ProjectID, ExpenseDescription, ExpenseAmount, ExpenseCodeID, AttachedRct, SubmittoExpRep
FROM OPENXML(@intDoc, '/ArrayOfTimeCardExpense/TimeCardExpense', 2)
WITH ( ExpenseRptID int 'ExpenseRptID',
ExpenseDate datetime 'ExpenseDate',
ProjectID int 'ProjectID',
ExpenseDescription nvarchar(510) 'ExpenseDescription',
ExpenseAmount money 'ExpenseAmount',
ExpenseCodeID int 'ExpenseCodeID',
AttachedRct bit 'AttachedRct',
SubmittoExpRep bit 'SubmittoExpRep')
-- check for error
IF @@ERROR <> 0
GOTO ErrorHandler
-- remove XML doc from memory
EXEC sp_xml_removedocument @intDoc
SET @bolOpen = 0
INSERT OPS_TimeCardExpenses(TimeCardID, ExpenseRptID, ExpenseDate, ProjectID, ExpenseDescription, ExpenseAmount, ExpenseCodeID, AttachedRct, SubmittoExpRep)
Values(@NewTimeCardID, ExpenseRptID, ExpenseDate, ProjectID, ExpenseDescription, ExpenseAmount, ExpenseCodeID, AttachedRct, SubmittoExpRep)
select @NewTimeCardID, ExpenseRptID, ExpenseDate, ProjectID, ExpenseDescription, ExpenseAmount, ExpenseCodeID, AttachedRct, SubmittoExpRep
from @tempXMLTimeCardExpense
-- check for error
IF @@ERROR <> 0
GOTO ErrorHandler
-- For time worked...
INSERT @tempXMLTimeCardWorked(TimeCardID, DateWorked, ProjectID, WorkDescription, BillableHours, BillingRate, WorkCodeID, Location)
SELECT @NewTimeCardID, DateWorked, ProjectID, WorkDescription, BilliableHours, BillingRate, WorkCodeID, Location
FROM OPENXML(@intDoc, '/ArrayOfTimeCardWorked/TimeCardWorked', 2)
WITH ( DateWorked DateTime 'DateWorked',
ProjectID datetime 'ProjectID',
WorkDescription nvarchar(max) 'WorkDescription',
BilliableHours float 'BilliableHours',
BillingRate money 'BillingRate',
WorkCodeID int 'WorkCodeID',
Location nvarchar(50)'Location')
-- check for error
IF @@ERROR <> 0
GOTO ErrorHandler
-- remove XML doc from memory
EXEC sp_xml_removedocument @intDoc
SET @bolOpen = 0
INSERT OPS_TimeCardHours(TimeCardID, DateWorked, ProjectID, WorkDescription, BillableHours, BillingRate, WorkCodeID, Location)
Values(@NewTimeCardID,DateWorked, ProjectID, WorkDescription, BillableHours, BillingRate, WorkCodeID, Location)
select @NewTimeCardID ,DateWorked, ProjectID, WorkDescription, BillableHours, BillingRate, WorkCodeID, Location
from @tempXMLTimeCardWorked
-- commit transaction, and exit
COMMIT TRANSACTION
set @Result = @NewTimeCardID
RETURN 0
-- Error Handler
ErrorHandler:
-- see if transaction is open
IF @@TRANCOUNT > 0
BEGIN
-- rollback tran
ROLLBACK TRANSACTION
END
-- set failure values
SET @Result = -1
RETURN -1
go
View 1 Replies
View Related
Nov 19, 2007
Can anyone please give me the equivalent tsql for sql server 2000 for the following two queries which works fine in sql server 2005
1
-- Full Table Structure
select t.object_id, t.name as 'tablename', c.name as 'columnname', y.name as 'typename', case y.namewhen 'varchar' then convert(varchar, c.max_length)when 'decimal' then convert(varchar, c.precision) + ', ' + convert(varchar, c.scale)else ''end attrib,y.*from sys.tables t, sys.columns c, sys.types ywhere t.object_id = c.object_idand t.name not in ('sysdiagrams')and c.system_type_id = y.system_type_idand c.system_type_id = y.user_type_idorder by t.name, c.column_id
2
-- PK and Index
select t.name as 'tablename', i.name as 'indexname', c.name as 'columnname' , i.is_unique, i.is_primary_key, ic.is_descending_keyfrom sys.indexes i, sys.tables t, sys.index_columns ic, sys.columns cwhere t.object_id = i.object_idand t.object_id = ic.object_idand t.object_id = c.object_idand i.index_id = ic.index_idand c.column_id = ic.column_idand t.name not in ('sysdiagrams')order by t.name, i.index_id, ic.index_column_id
This sql is extracting some sort of the information about the structure of the sql server database[2005]
I need a sql whihc will return the same result for sql server 2000
View 1 Replies
View Related
May 12, 2008
hi I have developed one tool which will show the realtime data of memory,processor, disk and Network...these data will change foe every second...
i want to store that data into the SQL server...is there any script to do this?...whether i need to do some scheduling?.....can anyone help me out please?...
Thnks in advance...
View 10 Replies
View Related
May 12, 2008
Hi,
I have developed one tool in ASP.NET(C#) which will show the realtime data of memory,processor,disk and memory which will refresh for every second...
i want to store this data into the sql server...is it possible to store the dynamic data?...if not how can i achieve this?...
evev i want to store the performance of all the remote servers which are in the intranet....is it possible to do?...how to achieve this?.. can anyone help me out...?
View 4 Replies
View Related
Apr 28, 2006
Hello
When i execute the Management Studio Express how can i verify (or define or ...) my server name? (If i choose Browse for servers i can´t find any of them local or network servers)
I have to choose windows authentication or sql server authentication?
Sorry about my basic questions :)
View 1 Replies
View Related
Mar 5, 2007
Hello evrybody..........
hope u all r doing fine ...well i hve a little problem that i hve installed sql server2005 express edition on my machine and now i just want to import my clients database which is on Acess but m not getting DTS wizard anywhere in 2005 edition so what should i do....infact i found the exe of dtswizrd in program files microsoft sql server folder but when i hit that exe it throws error that one of the file is could not be loaded it is SQLSVC.RLL file...so what should i do shall i reinstall my package ???and even m not confirmed that the free packageof 2005 which i hve downloaded by download center..wheather microsoft gives the whole package or not???like because here in my package i don't find DTS wizard anywhere like we have in 2000 package....
So does anybody help me Plz?????
hope for a positive reply from all u experts .........
thnks
View 7 Replies
View Related
Jun 7, 2008
We have SQL Server 2005 on windows 2003 server +SP2. In the application log I noticed the following errors during .
Event Type:Error
Event Source:MSSQLSERVER
Event Category:(3)
Event ID:19019
Date:6/6/2008
Time:10:28:13 PM
User:N/A
Computer:COMP NAME
Description:
[sqsrvres] printODBCError: sqlstate = 08S01; native error = 0; message = [Microsoft][SQL Native Client]Communication link failure
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
Data:
0000: 4b 4a 00 40 01 00 00 00 KJ.@....
0008: 08 00 00 00 53 00 51 00 ....S.Q.
0010: 4c 00 43 00 4c 00 55 00 L.C.L.U.
0018: 53 00 00 00 00 00 00 00 S.......
When error occur at this time excute a procedure to export table in csv file use bcp and copy this file in Network folder
so what should be error?
View 1 Replies
View Related
Oct 18, 2006
hi every body ; Ineed sql server 2005 material
View 5 Replies
View Related
Apr 22, 2008
Hi,
When i execute this query
SELECT *
FROM INFORMATION_SCHEMA.SCHEMATA
WHERE SCHEMA_NAME = 'a424465';
I can see the..
CATALOG_NAME SCHEMA_NAME SCHEMA_OWNER ...
schema1 schema2
I wanna change the SCHEMA_OWNER to be schema1...
How can be done???
Plz Help me ASAP..
View 1 Replies
View Related
May 29, 2008
hi
how are the use alerts in sql server2005,
and which alert type used in maximum and how to performaing our database
I would like to get user experiences
View 3 Replies
View Related
Aug 20, 2006
Hi there i need an advice on replication in sql2005
i've heared that i can't make replication between two cluster servers installed on them sql2005 and they are in different domains so please can you tell me is that true and if is what can we do to solve this because they are in different places and we can't give them the same domains of IPs
thanks
View 3 Replies
View Related
Feb 21, 2006
hi.
I am too green in sql2005.
so the problem is with data import from csv or txt or access files to sql mobile database.
at internet i fount that tis is wery simple but i can not find how?
so dts wizzard have not this function.
coul someone provide directly steps which i shoud do to import/export data from sdf db
i have vs2005 and sql2005
View 7 Replies
View Related
Jan 4, 2007
i am novice to SQL server 2005 ,i had sql server 2005 working fine but today i found MSSQLSERVER service not runing i tried but could not make it ,i have VIA disabled but still not working i get the message when i try to start the service it says" MSSQLSERVER service started and stopped. some services automatically stop when they have no work to do."
i guess it has some problem with TCP IP settings coz in the errorlog it says "could not listen on TCP IP port 1433 port already open " i dont know why ?
any help would be appriciated.
thanks
zahid
View 3 Replies
View Related
Mar 15, 2008
Hi. I have a vista (home premium) based laptop. I want to insatll sql server 2005 on it. I had earlier tried it but no luck, I think it never got installed. It didn't showed any error messages either. How can I do this?? Do I need some kind of patch or Add-Ins or what?? HELP NEEDED!!!!
THANKS!!!!
View 3 Replies
View Related
Mar 31, 2008
Hi. I'm a newbie for sql server. I have a laptop loaded with win vista home premium edition. I installed sql server 2005 developer edition service pack 1 on it. It said that this version is not supported by vista so upgrade it with sp2, so I did the same. I upgraded it to sql express 2005. Now it got installed but it doesn't let me create new database and displayed the msg "LOGON FAILED FOR 'USER' " . I thought of reinstalling it. But now it is not uninstalling. I tried it through add/remove programs. The 'sql server management tools' is not visible in the start program list,but 'sql server 2005' and some other components of it are visible in add/remove programs. Then I tried using command prompt that was given in microsoft's site only http://support.microsoft.com/?kbid=909967#
Step 2: Run the command to uninstall the SQL Server components
c:"%ProgramFiles%Microsoft SQL Server90Setup BootstrapARPWrapper.exe /Remove"
But this was also of no help. Now What should I do??? Need your HELP!!!!!!!!!!!!!!
THANKS!!
View 3 Replies
View Related
Jan 10, 2007
Hi Guys
I have a table in which one of the column name is "NAME".
I have to write query in which column is not null and if there is something then check for 'trust' or 'trustee' in the string. and if found don't pull that record. skip it
who do i do these. Any help please.
View 2 Replies
View Related
Mar 25, 2008
HiI'm looking to return rows from a table where a column is LIKE a keyword. This is my current code:SELECT DISTINCT business_name FROM Table WHERE business_name LIKE @keyword + '%' ORDER BY business_name ASCThe problem with this is that if a business is called "The White Ship Inn", and the keyword to match is "White Ship" it will not match. If i put another wild card in front of @keyword then this finds too many matches - i need it to match against columns which either start with the keyword, or have a whitespace in front of them. Is there some kind of T-Sql i can use or will i have to go down the regex route (using this (http://www.codeproject.com/KB/mcpp/xpregex.aspx)) ?cheers
View 2 Replies
View Related
May 6, 2004
Does SqlServer support Regular expression?
I want to know if it's avilable or not...
And if it's not available, I want to know any other efficient way to validate string.. manipulating Regular expression style validation.
Thank you all...
View 6 Replies
View Related
Sep 6, 2005
I need to remove all the [ and ] in every sql stmt where they are usedto close encircling numeric value, fyi, all these sql stmt areconverted from an Access db. For instance,select *from XYZtblwhere fieldA = [1] or fieldA = [2] or fieldA = [3]to beselect *from XYZtblwhere fieldA = 1 or fieldA = 2 or fieldA = 3-- and of course I'd have written in as follows, but that's not-- the pointselect *from XYZtblwhere fieldA IN (1,2,3)Thanks.
View 5 Replies
View Related
Aug 26, 2006
Dear !From Couple of days i waste my hours on it. but i fail to solve this problem.Can we use SQL server 2005 and Login Control of ASP.NET. when i try to use it gives me an error. An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) May be it works with SQL Express Edition as in learning videos. But i want to use it wit SQL server 2005. Very intersting thing i create the Mange City Page. in this page it works perfect. in this page city table takes a parameter from dropdownlist. perfectly working. but with login page it gives me error.
View 1 Replies
View Related
Dec 4, 2007
hi all,
my employee table contains 'salary' column. Data type-->int.
now i have to write a query to see hike of all employees using the condition
for salaray >10000 and < 20000 give 10%
View 4 Replies
View Related
Jun 20, 2008
Hi,
I created the following table in which i created full text indexing for DocDatafld and TypeColumn was used as Type Column for DocDataFld field. I store Document name in the DocumentTitlefld and want to get the Document name and Document and want to display it in the front end application and give url for the document.
Documentidfld bigint
Documenttitlefld varchar
MimeTypefld varchar
DocDatafld varbinary(MAX)
TypeColumn varchar
and i am using the following query to get the contents, but not able to get the column values.
select documenttitlefld,docdatafld from Documentdatatbl Freetext(DocDatafld,'C')
Please help
View 2 Replies
View Related