Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Friday, March 30, 2012

Relationships in MSDE - how do I do it?

Hi
I am using the Web Matrix Project to write a .NETapplication. I have set up a database using MSDE which Iaccessed through the Web Matrix Project to start with. I have nowfound the Web Data Administrator which I use to backup my database andhelp to transfer it to the Server where I hope to run this application(if I ever get it finished!).
I need to set up some relationships between database tables but cannotsee a way to do this. SQL Server Books on Line referes toEnterprise Manager which I believe ships with the full MS SQL Serverpackage (and costs a package). I am doing this on ashoe-string. Any ideas on how to do it?
Thanks in advance.
Mike
CREATE TABLE order_part
(order_nmbr int,
part_nmbr int
FOREIGN KEY REFERENCES part_sample(part_nmbr)
ON DELETE NO ACTION,
qty_ordered int)
GO

you could do an alter table if its already there|||Hi DeveloperMCDBA
I did not realise I could create a table using a StoredProcedure. It certainly takes me longer than just using theWebMatrix but I seem to be getting there. Many thanks for thehelp - much appreciated.
Mike

Friday, March 9, 2012

regular expressions in transact sql

hi guys,

i need some help tp write code in order to search the string ( regular expressions) in t- sql.

e.g.

when a user enters [A-Z] it means any alphabet from 'A' to 'Z'...

similarly [0-9] means any digit.

the problem is: when user enters [0-6] and the string received contains digit 5 it should return true but if it contains 7 it should return false.

so how do i read the [A-Z] as a range of characters in t-sql?

hi,

In sql server it is not exactly regular expression, it is called wild card pattern. in other words it is simplified reqular expression,

as of now SQL Server Like operator only work with following operators

% - Zero or any number of chars

_ - Single Char

[] - Single Char in given range

Cake - Single Char not in given range

if you want to utilize the exact regular expression on your query then the best solution will be CLR Functions.(SQL Server 2005).

For fixed validation (only numbers & only alphabets) i achived the following function,


Create Function dbo.IsMatching(@.Value as varchar(1000), @.Pattern as varchar(100))
returns bit as
Begin
Declare @.Len as int;
Declare @.SearchPattern as varchar(8000);
Declare @.Result as Int;

Select @.Len = Len(@.Value);

While @.Len>0
Begin
Select @.SearchPattern = Isnull(@.SearchPattern,'') + @.Pattern;
Select @.Len = @.Len -1;
End
Select @.Result = Case When @.Value Like @.SearchPattern Then 1 Else 0 End;
Return @.Result;
End

Go

select dbo.IsMatching('SQLServer','[A-Z]') as Result

Result : 1

select dbo.IsMatching('SQL Server','[A-Z]') as Result

Result : 0 --Space on String

select dbo.IsMatching('SQL Server','[A-Z ]') as Result

Result : 1 --Space added on Pattern

select dbo.IsMatching('12453','[1-5]') as Result

Result : 1

select dbo.IsMatching('12463','[1-5]') as Result

Result : 0

|||

thanks mani,

got the [A-Z] and [^a-z] concept.

my other requirements are to match zero or more characters and to match one or more characters.

e.g. T*he should match he, the, tthe, ttttthe.. etc.

and t+ho should match tho, thho, thhhhhhho, thhhhhhhhhhhhhho.. etc.

the above operators i have used in VC++,

do they work in t-sql too?

|||If you need regular expression and your platform is sqlserver 2005 you can use a CLR strored procedure. If you need help on this post a question on the .net framework inside sql server forum
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=86&SiteID=1|||

Yes.. if you want to find the repeated chars you can use the following condtions....

columnname not like '%aaa%'
and columnname not like '%bbb%'
and columnname not like '%ccc%'
and columnname not like '%ddd%'
and columnname not like '%eee%'
and columnname not like '%fff%'
and columnname not like '%ggg%'
and columnname not like '%hhh%'
and columnname not like '%iiii%'
and columnname not like '%jjj%'
and columnname not like '%kkk%'
and columnname not like '%lll%'
and columnname not like '%mmm%'
and columnname not like '%nnn%'
and columnname not like '%ooo%'
and columnname not like '%ppp%'
and columnname not like '%qqq%'
and columnname not like '%rrr%'
and columnname not like '%sss%'
and columnname not like '%ttt%'
and columnname not like '%uuu%'
and columnname not like '%vvv%'
and columnname not like '%www%'
and columnname not like '%xxx%'
and columnname not like '%yyy%'
and columnname not like '%zzz%'

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=996813&SiteID=1

If you want to utilize the exact regular expression as i said earlier you can go for CLR Functions..

Regular Expressions in SQL Server 2005

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

OK. At this point I'm pretty sure that this can be accomplished through the common language runtime. Can someone confirm this?

-David

|||

Yes with CLR intergration in SQL Server 2005, you can write CLR Stored procedures in VB or C#. By referring to System.Text.RegularExpressions namespace you can add regular expression support to your stored procs. Here are couple of links to get you started:

http://msdn2.microsoft.com/en-us/library/ms131094(SQL.90).aspx

http://www.dotnetfun.com/articles/sql/sql2005/SQL2005CLRSProc.aspx

|||

Thanks for the links. I've been using regex in my VBA project, and MS seems to have done a pretty decent job implementing it. I'm a PERL regex expert from long before which of course helps.

Thanks again.