June 25, 2009 at 8:55 am
Sinshith S Anand (6/23/2009)
Please contribute ur ideas...I have got only one correct answer....
Really? What is your definition of correct?
I've seen answers here that meet your requirements even if they aren't the best.
June 25, 2009 at 2:58 pm
jdurandt (6/25/2009)
Here is one that uses a cartesian product:
I love this one! Would use UNION ALL instead of UNION, but still...:-)
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
June 26, 2009 at 12:42 am
According to OP, he wants the numbers PRINTED, because they then are stored in the log file.
N 56°04'39.16"
E 12°55'05.25"
June 26, 2009 at 12:51 am
I took the "OP requires a PRINT" as a challenge... 😀
How about this?
Set NOCOUNT ON
Declare @result varchar(8000)
set @result = ''
Declare @Numbers Table (val int)
Insert into @Numbers
Select Ones.val + Tens.val
from (Select 0 as val
union Select 1
union Select 2
union Select 3
union Select 4
union Select 5
union Select 6
union Select 7
union Select 8
union Select 9) AS Ones
cross join
(Select 0 as val
union Select 10 as val
union Select 20
union Select 30
union Select 40
union Select 50
union Select 60
union Select 70
union Select 80
union Select 90) AS Tens
Where Ones.val + Tens.val >= 1
Order by Ones.val + Tens.val
Update @numbers
Set val = val,
@result = @result + Cast(val as varchar) + char(13)
print @result
June 26, 2009 at 1:40 am
Peso (6/26/2009)
According to OP, he wants the numbers PRINTED, because they then are stored in the log file.
I considered that, but seeing as one of his initial examples just had a select and no print, I figured he just wanted them displayed.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 26, 2009 at 2:05 am
Peso (6/26/2009)
According to OP, he wants the numbers PRINTED, because they then are stored in the log file.
create database [04C87CAC-9AA8-4465-AC6E-921060A604FF];
go
alter database [04C87CAC-9AA8-4465-AC6E-921060A604FF] set recovery simple;
go
use [04C87CAC-9AA8-4465-AC6E-921060A604FF];
go
checkpoint
select * from fn_dblog(null, null)
print 'hello'
select * from fn_dblog(null, null)
go
use master
go
drop database [04C87CAC-9AA8-4465-AC6E-921060A604FF];
? :unsure:
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
June 26, 2009 at 6:24 am
Sinshith S Anand (6/25/2009)
Still many methods are there.....Please contribute your ideas
Ummmmm... WHY? You writing a book or what?
See ya...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 26, 2009 at 6:32 am
Paul White (6/24/2009)
Fastest possible implementation:
I take it all back 🙁
This is faster:
[font="Courier New"]PRINT 1
PRINT 2
PRINT 3
...
PRINT 100[/font]
You can have that one for your book for free!
Paul
edit: stupid font tags :angry:
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
June 26, 2009 at 7:03 am
Hi friends,
I am really happy to see Lots of ideas....You can visit my blog also
http://sinshith.wordpress.com/
And let me know your comments...I started writing blog recently
June 26, 2009 at 7:40 am
Sinshith S Anand (6/26/2009)
Hi friends,I am really happy to see Lots of ideas....You can visit my blog also
http://sinshith.wordpress.com/
And let me know your comments...I started writing blog recently
You still haven't answered my question. What do you consider correct??
June 26, 2009 at 7:49 am
I think you need to test the solutions in your blog first.
The "Procedure for droping all constraints from a table" won't work because of this (amongst other things):-
WHILE(@@FETCH_STATUS-1)
It would also be a good idea to state which version of SQL Server they apply to... DATE and DATETIME2 aren't valid in all versions.
June 26, 2009 at 7:57 am
Credit where it's due for giving it a go. 🙂
I agree that you should personally test code you post - for credibility's sake.
Paul
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
June 26, 2009 at 8:06 am
Credit where it's due for giving it a go
Hope my post didn't sound too critical... it was meant as constructive criticism:blush:
June 26, 2009 at 8:07 am
Ian Scarlett (6/26/2009)
I think you need to test the solutions in your blog first.The "Procedure for droping all constraints from a table" won't work because of this (amongst other things):-
WHILE(@@FETCH_STATUS-1)
Also foreign keys have to be dropped before the primary keys/unique constraints that they reference.
Are you intending to put all these print 1..100 answers on your blog as well?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 26, 2009 at 8:20 am
Ian Scarlett (6/26/2009)
Credit where it's due for giving it a go
Hope my post didn't sound too critical... it was meant as constructive criticism:blush:
I read it as constructive criticism 🙂 😎
edit: reworded to clarify my meaning
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
Viewing 15 posts - 16 through 30 (of 79 total)
You must be logged in to reply to this topic. Login to reply