bits and bytes of my life experiences
With related to my earlier post which demonstrated how to retrieve only numbers in a string using C#, this is how you can do it using TSQL in SQL Server. This will be also become handy if you want to do this in a backend process (SP, Trigger, etc). This is a UDF which you can reuse in your TSQL codes.
USE [DBNAME]
GO
/****** Object: UserDefinedFunction [dbo].[fn_filternumbers] Script Date: 11/27/2009 17:59:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[fn_filternumbers]
(
@Src nvarchar(255)
)
RETURNS nvarchar(255)
AS
BEGIN
declare @Res nvarchar(255)
declare @i int, @l int, @c char
select @i=1, @l=len(@Src)
SET @Res = ''
while @i<=@l
begin
set @c=upper(substring(@Src,@i,1))
IF @c IN ('0','1','2','3','4','5','6','7','8','9')
SET @Res = @Res + @c
set @i=@i+1
end
return(@res)
END
You can use this function in the following manner;
select telephone, dbo.fn_filternumbers(telephone) from users
This will return telephone numbers by removing white spaces, characters and will only return numbers. (i.e +94 (475) 849 984 would return 94475849984)
Please feel free to drop a comment if you have any question on this.
I wanted to retrieve only the number in a string to clean up some telephone numbers users have entered in a system today. So I came across with this nice Regular Expression it is really simple and most importantly it was the fastest method I could found. Here is the code;
public String returnonlyNumbers(String stringValue)
{
return string.Join(null, System.Text.RegularExpressions.Regex.Split(stringValue, "[^\\d]"));
}
The above code would return only the numbers in any given string. For example if you pass the string “+94 (084) 849748 489748” to this method it would return “94084849748489748”.
Hope someone would find this beneficial.
Time travelling is one of the most fascinating concepts in the world of science fictions. Is time travel possible in the real world? This is a question which most of us would have asked from our selves at least once in our life. Anyway it will be a question without a proper answer for another few decades or more.
At least it has become a reality for the web. Yes you can do travel through time in the web. For a example if you want to go to yahoo.com as it was in 1998, it is really possible with the Way Back Machine. The internet archive a non-profit organization is having the worlds biggest digital library of web archives. Apart from the way back machine they also do provide various other tools to analyze the web archive for researchers, students and general public for free.
So go ahead and play around with the Way Back Machine http://web.archive.org/collections/web/advanced.html
2. Then you have to open TCP/IP connections to your SQL Server. To do this you have to use the "SQL Server Configuration Manager" tool. You can open this tool by either typing "SQLServerManager10.msc" as a Run command or through the Programs menu as follows
SQL Server 2008 -> Configuration Tools -> SQL Server Configuration Manager
In the right hand side click on
"SQL Server Network Configuration" -> "Protocols for MSSQLSERVER" -> Right click on TCP/IP in the right hand side list -> Select Enable.
Now you will have to restart the SQL Server service.
3. You can restart the service by either going into the Services in the control panel or from the SQL Server Configuration Manager screen itself. Following screen shows how to do it from the Configuration Manger tool. In the services you have to restart the service named "SQL Server (MSSQLSERVER)" service.
4. Now you may be able to access your SQL Server from a remote client or application if you are using Windows XP or a Server version. But if you are using Windows Vista you may still not be able to access your server if the Windows Firewall is enabled. To solve this issue, you have to enable SQL Server TCP/IP port which is 1433 in the windows firewall. To do this go to;
Control Panel -> Windows Firewall -> Click on Change Settings hyperlink -> Exceptions Tab -> Add Port -> Give any meaningful name for Name textbox -> In to the Port Number textbox 1433 -> Protocol should remain as TCP/IP -> Click OK.
It's recommended to restart the firewall.
These steps should solve your issue with remote connections.