Archive for September, 2007

How can I get string format for a number?

Thursday, September 27th, 2007

 Q:  How can I get string format for a number? For example I’d like to print 123 in strings like “one hundered twenty three”.

Bryan Oliver says:  OK, you asked for it – this one is somewhat long (anybody have a more brief suggestion?):

–**************************************

– Name: A Number To Words function Version 2
– Description:Converts a numeric value to words, i.e, 123
– will return ONE HUNDRED TWENTY THREE

– Inputs:@num – a numeric value

– Returns:The number in words

– **************************************
– Assumes:Copy and paste the code into
– Query Analyzer and hit F5, then you can
– use it just as you would use other SQL functions.
– **************************************

CREATE FUNCTION NumToWords_Ver2(@num numeric)
RETURNS varchar(1000)
AS

BEGIN
DECLARE @cNum varchar(20)
SET @cNum = @num
DECLARE @len int
SET @len = LEN(@num)
DECLARE @place int
SET @place = 0
DECLARE @digit varchar(1), @tens varchar(2)
DECLARE @res varchar(1000)
DECLARE @nullStr int
SET @res = ”
DECLARE @tblNum TABLE(Num int, NumStr varchar(20))
INSERT INTO @tblNum
SELECT 1, ‘ ONE’ UNION
SELECT 2, ‘ TWO’ UNION
SELECT 3, ‘ THREE’ UNION
SELECT 4, ‘ FOUR’ UNION
SELECT 5, ‘ FIVE’ UNION
SELECT 6, ‘ SIX’ UNION
SELECT 7, ‘ SEVEN’ UNION
SELECT 8, ‘ EIGHT’ UNION
SELECT 9, ‘ NINE’ UNION
SELECT 10, ‘ TEN’ UNION
SELECT 11, ‘ ELEVEN’ UNION
SELECT 12, ‘ TWELVE’ UNION
SELECT 13, ‘ THIRTEEN’ UNION
SELECT 14, ‘ FOURTEEN’ UNION
SELECT 15, ‘ FIFTEEN’ UNION
SELECT 16, ‘ SIXTEEN’ UNION
SELECT 17, ‘ SEVENTEEN’ UNION
SELECT 18, ‘ EIGHTEEN’ UNION
SELECT 19, ‘ NINETEEN’ UNION
SELECT 20, ‘ TWENTY’ UNION
SELECT 30, ‘ THIRTY’ UNION
SELECT 40, ‘ FOURTY’ UNION
SELECT 50, ‘ FIFTY’ UNION
SELECT 60, ‘ SIXTY’ UNION
SELECT 70, ‘ SEVENTY’ UNION
SELECT 80, ‘ EIGHTY’ UNION
SELECT 90, ‘ NINETY’
DECLARE @hundred varchar(200)
SET @hundred = ”
DECLARE @nStr varchar(20)
SET @place = @len
WHILE @place > 0

BEGIN
SET @place = @place – 1
SET @nStr = NULL
SET @digit = SUBSTRING(@cNum, @len-@place, 1)
IF (@place+1) % 3 = 1 –One’s place
BEGIN
SELECT @nStr = NumStr FROM @tblNum WHERE Num = @digit
IF @nStr IS NOT NULL
SET @hundred = @nStr
IF LEN(@hundred) > 0
SET @res = @res + @hundred + CASE @place / 3
WHEN 0 THEN ”
WHEN 1 THEN ‘ THOUSAND’
WHEN 2 THEN ‘ MILLION’
WHEN 3 THEN ‘ BILLION’
WHEN 4 THEN ‘ TRILLION’
WHEN 5 THEN ‘ QUADRILLION’
WHEN 6 THEN ‘ QUINTILLION’
END
SET @hundred = ”
END
IF (@place+1) % 3 = 0 –Hundred’s place
BEGIN
SELECT @nStr = NumStr FROM @tblNum WHERE Num = @digit
IF @nStr IS NOT NULL
SET @hundred = @nStr + ‘ HUNDRED’
SET @tens = SUBSTRING(@cNum, @len-@place+1, 2)
IF LEN(@hundred) > 0 AND (@tens = ” OR @tens = ‘00′)
SET @res = @res + @hundred + CASE (@place+1) / 3
WHEN 0 THEN ”
WHEN 1 THEN ”
WHEN 2 THEN ‘ THOUSAND’
WHEN 3 THEN ‘ MILLION’
WHEN 4 THEN ‘ BILLION’
WHEN 5 THEN ‘ TRILLION’
WHEN 6 THEN ‘ QUADRILLION’
WHEN 7 THEN ‘ QUINTILLION’
END
ELSE
SET @res = @res + @hundred
SET @hundred = ”
END
ELSE IF (@place+1) % 3 = 2 –Ten’s place
BEGIN
SET @tens = SUBSTRING(@cNum, @len-@place, 2)
SELECT @nStr = NumStr FROM @tblNum WHERE Num = @tens
IF @nStr IS NULL
BEGIN
SELECT @nStr = NumStr FROM @tblNum WHERE Num = @digit * 10
SET @digit = SUBSTRING(@cNum, @len-@place+1, 1)
SELECT @nStr = @nStr + NumStr FROM @tblNum WHERE Num = @digit

END
SET @hundred = @nStr
IF LEN(@hundred) > 0
SET @res = @res + @hundred + CASE (@place+1) / 3
WHEN 0 THEN ”
WHEN 1 THEN ‘ THOUSAND’
WHEN 2 THEN ‘ MILLION’
WHEN 3 THEN ‘ BILLION’
WHEN 4 THEN ‘ TRILLION’
WHEN 5 THEN ‘ QUADRILLION’
WHEN 6 THEN ‘ QUINTILLION’
END
SET @place = @place – 1
SET @hundred = ”
END

END
RETURN @res
END

Technorati Tags:
, , ,

How can I convert from MySQL to MSSQL server 2005 ?

Thursday, September 27th, 2007

Q:  How can I convert from MySQL to MSSQL server 2005 ?

Iain Kick says:   I would take a look at this white paper by microsoft on converting from MYSQL to SQL Server 2000 it is a very similiar process for 2005.

Technorati Tags:
, ,

PASS 2007 – check out the pictures!

Thursday, September 27th, 2007

Not sure if anybody was able to attend PASS this year in Denver, CO – if not, then live vicariously through these pictures on Flickr!  These pics are taken (mostly) from the vantage of the Quest Software booth that was at the show, just a heads up – don’t worry, there’s no advertising in these photos, just pics of some of the attendees, booth staff and activities from the show.  Take a look and maybe we’ll see you next year!

 Andy Grant

Storage Expo – London & IT Forum – Barcelona

Wednesday, September 26th, 2007

Hi,

I will be attending

Storage Expo in London

October 17th – 18th

http://www.storage-expo.com/

IT Forum in Barcelona

November 12th – 16th

http://www.mseventseurope.com/teched/07/itforum/content/Pages/Default.aspx

So, if you are attending, please come over to the Quest Software stand and say hello. We will be providing demos of Quest products, but if you just want to have a chat about SQL Server then that would be great!

 Iain Kick

Is there any provision for recovering data after executing a DELETE?

Tuesday, September 25th, 2007

Q:   I have a table name “Test”.There are few records in the table. Now i execute a query “Delete from Test ” so this query will delete all the data from the table “Test” . Now my question is that Is there is any provision to recover that data just after executing delete query . I mean to say i executed delete query mistakely so i want to recover that data.

Iain Kick says:   Well, that’s sort of a tough one. There is no native provision for doing this type of data recovery unless you put the DELETE statement in a transaction (always good practice) then you can issue a rollback if required. Being able to rollback transactions is a crucial task for administering any database, so taking the precaution to include these DELETE’s in a transaction is something to keep front of mind.

Technorati Tags:
, ,

Suggested reference sites for Triggers and Indexes in SQL Server

Tuesday, September 25th, 2007

Bryan Oliver says:   We here at SQLServerPedia have received quite a few questions related to the creation/implementation of database objects such as Triggers and Indexes. I would like to provide a short list of articles and postings related to these DBO’s, their creation and their useage. If you’re a beginner and not very familiar (or even if you just want to brush up) please take some time to check these out – they helped me!

Thanks!

Here is some articles on triggers.

http://www.devarticles.com/c/a/SQL-Server/Using-Triggers-In-MS-SQL-Server  

http://www.sql-server-performance.com/nn_triggers.asp  

http://www.codeproject.com/database/SquaredRomis.asp  

And some articles on indexes

http://www.odetocode.com/Articles/70.aspx  

http://www.sql-server-performance.com/optimizing_indexes.asp  

http://www.devx.com/getHelpOn/Article/10016

How to do concurrent backups on a local and remote machine running SQL Server?

Tuesday, September 25th, 2007

Q:  I want to take backup of sql server database at my local machine and concurrently at remote machine through scheduler, please tell me how to do this?

Iain Kick says:   This is new functionality for SQL Server 2005 and is only in the Enterprise edition. In order to get a detailed explanation on Mirrored backups to disk and tape, MS books online has this written up and ready to go – check the link here

Technorati Tags:
, ,

How do I deploy SQL Server Express?

Monday, September 24th, 2007

Q:  I develop web applications on my PC using SQL Server Express. 1. Can these applications be deployed still using Express? 2. If not, what is required to convert the essential parts to SQL Server

Bryan Oliver says:  I can suggest some great articles written by Microsoft themselves regarding deploying SQL Server Express check these over to get a good head start, here they are:

http://msdn2.microsoft.com/en-us/library/ms165639.aspx
http://msdn2.microsoft.com/en-us/library/bb264562.aspx

Technorati Tags:
,

Can you help me to run a stored proc in my VB application?

Monday, September 24th, 2007

Q:  I have used SQL procedure in my vb6 application. The application is client server, on some clients procedure runs fine. But on some clients, procedure does not run. It does not show any error – what should be done?

Kevin Kline says:  The answer to this problem might not be what you want to hear. In a nutshell, your problem illustrates that your VB6 application does not have enough internal logging.

You should add code to the application that allows you to enable a “Debug” mode that tells you everything that the application is doing. It may be possible that the error isn’t in SQL Server at all, but is in your VB6 application and is not properly invoking the stored procedures.

To further learn what’s happening from the SQL Server side of things, bring up SQL Profiler and trace the sessions that are working and also not working. You can then see all of the commands that are being sent to the SQL Server and correlate that activity to any failed stored procedure calls.

If you’re not familiar with SQL Profiler, read about it in the SQL Server Books On-Line. It’s well documented there.

Technorati Tags:
, , , , ,

Where can I learn what is wrong with my SQL job or DTS package ?

Monday, September 24th, 2007

Q:  I am using SQL server and i configured a dts package that imports paradox database to my sql 2000 i scheduled the dts package for 3 times a day but it gives an unknown error that i can only trace in event logs and i cant get detailed error messages to fix it.Where can i learn what is wrong with my sql job or dts package ? where can i get a detailed error message??

Kevin Kline says:  Well, you didn’t submit the error number on this, which would be more helpful, but in the meanwhile, here’s a general troubleshooting process to follow:

1. Write down the error number. If you don’t have the error number, write down as much of the error as possible.
2. Press Ctrl-PrtSc to save a screenshot of the error msg to the clipboard. Save it in Paint for later reference.
3. Go to http://support.microsoft.com
4. Click the hyperlink “Switch to Advanced Search” in the upper right corner of the frame. Then:
A. In the “Search Product” box, enter SQL Server, SQL Server 2000, or SQL Server 2005.
B. In the “For” box, enter the error number and/or the error message.
C. You should be able to leave the rest of the choices as-is.
D. Make sure that Include boxes are checked: How-to Articles, Downloads, Troubleshooting, Guided Help, MSDN content, TechNet Content.
5. Click Search.

Now, look at the links that are returned and choose the one(s) that work best for your problem.

Hope this helps

Technorati Tags:
, , ,


Fatal error: Call to undefined function SEO_pager() in /home/ssp/webapps/htdocs/blog/wp-content/themes/newblogcity/archive.php on line 47