Showing posts with label t-sql. Show all posts
Showing posts with label t-sql. Show all posts

Sunday, February 19, 2012

Documented t-sql for file space ?

Hi There

I would like to write sql to check that space used by any given data file in SS2000.

sp_spaceused only returns the total space used by the DB or object in the DB, not for a specific data file.

DBCC SHOWFILESTATS does give me this information , but it is not documented in BOL, i would prefer not to use an undocumented command to ensure future use in later versions. Is DBCC SHOWFILESTATS an undocumented T-SQL command ? If so what documented t-sql command will provide me with this information ?

I could query system table's and work this out , but as mentioned this may not not work in future versions of SS.

Thanx

Dont worry, seems FILEPROPERTY function will do this for me , thanx

Friday, February 17, 2012

Document Job Steps

How can I script out the job steps along with the DTS, Sp or T-SQL code within the step. This info must be stored somewhere. How can I access it?

Hi,

You can script out jobs, including their job steps, by using SQL Server Management Studio. In SQL Server Books Online, see the topic "How to: Script Jobs Using Transact-SQL (SQL Server Management Studio)"

The URL within the Books Online browser is

ms-help://sql90/udb9/html/fd9e6497-87ca-4da8-b194-55c9d5b03cec.htm

Copy and paste this URL into the Books Online browser to locate this topic. As an alternative, you can also search on the topic name.

Let me know if you have any further questions.

Best regards,

Laurel Hale

Document Job Steps

How can I script out the job steps along with the DTS, Sp or T-SQL code within the step. This info must be stored somewhere. How can I access it?

Hi,

You can script out jobs, including their job steps, by using SQL Server Management Studio. In SQL Server Books Online, see the topic "How to: Script Jobs Using Transact-SQL (SQL Server Management Studio)"

The URL within the Books Online browser is

ms-help://sql90/udb9/html/fd9e6497-87ca-4da8-b194-55c9d5b03cec.htm

Copy and paste this URL into the Books Online browser to locate this topic. As an alternative, you can also search on the topic name.

Let me know if you have any further questions.

Best regards,

Laurel Hale

Tuesday, February 14, 2012

Do While Loop in T-SQL?

Is there a way to construct a Do While Loop in T-SQL. I didn't see any =
syntax in BOL for doing this. Essentially, I want to always run the the =
loop once, then check the loop expression to see if I can exit. In VB =
it would look something like this
Do
..
Loop While(something < 5)
Thanks,
--MichaelWhile (something < 5)
Begin
..do stuff
End
HTH
Thomas
"Raterus" <raterus@.hotmail.com> wrote in message
news:uf9oXJSRFHA.2932@.TK2MSFTNGP09.phx.gbl...
Is there a way to construct a Do While Loop in T-SQL. I didn't see any synt
ax
in BOL for doing this. Essentially, I want to always run the the loop once,
then check the loop expression to see if I can exit. In VB it would look
something like this
Do
..
Loop While(something < 5)
Thanks,
--Michael|||Let me be a bit more descriptive, "something" is set from within the =
loop. What I'm trying to avoid is having to set "Something" before the =
loop, and also in the loop, repeating the exact same syntax. A normal =
While loop won't work without duplicating the code from within the loop.
Do
Something =3D GetSomething()
DoSomething(Something)
Loop While (Something < 5)
"Thomas" <replyingroup@.anywhere.com> wrote in message =
news:OWtdcLSRFHA.2356@.TK2MSFTNGP14.phx.gbl...
> While (something < 5)
> Begin
> ...do stuff
> End
>=20
>=20
> HTH
>=20
>=20
> Thomas
>=20
>=20
> "Raterus" <raterus@.hotmail.com> wrote in message=20
> news:uf9oXJSRFHA.2932@.TK2MSFTNGP09.phx.gbl...
> Is there a way to construct a Do While Loop in T-SQL. I didn't see =
any syntax=20
> in BOL for doing this. Essentially, I want to always run the the loop =
once,=20
> then check the loop expression to see if I can exit. In VB it would =
look=20
> something like this
>=20
> Do
> ...
> Loop While(something < 5)
>=20
> Thanks,
> --Michael=20
>=20
>|||That's not the same as a do/while loop - with a do/while loop (as shown, or
in the C languages) the code in the loop runs at least once. A couple option
s:
1. Change your condition so it will always be true the first time; to
continue your example:
WHILE (something < 6) BEGIN ... END
2. Move the condition to an IF statement at the end of the loop:
WHILE (1=1)
BEGIN
-- code...
IF (something = 5) BREAK
END
3. Use a GOTO statement:
_LOOP:
-- ... CODE
IF (something < 5) GOTO _LOOP
"Thomas" wrote:

> While (something < 5)
> Begin
> ...do stuff
> End
>
> HTH
>
> Thomas
>
> "Raterus" <raterus@.hotmail.com> wrote in message
> news:uf9oXJSRFHA.2932@.TK2MSFTNGP09.phx.gbl...
> Is there a way to construct a Do While Loop in T-SQL. I didn't see any sy
ntax
> in BOL for doing this. Essentially, I want to always run the the loop onc
e,
> then check the loop expression to see if I can exit. In VB it would look
> something like this
> Do
> ...
> Loop While(something < 5)
> Thanks,
> --Michael
>
>|||That's an odd design pattern - declaring the variable for the exit condition
within the loop. If both GetSomething() and DoSomething(Something) are
deterministic then the condition will either always be false in which case
there's no reason to have it, or always be true in which case the loop will
never exit.
"Raterus" wrote:

> Let me be a bit more descriptive, "something" is set from within the loop. What I
'm trying to avoid is having to set "Something" before the loop, and also in the loo
p, repeating the exact same syntax. A normal While loop won't work without duplicat
ing
the code from within the loop.
> Do
> Something = GetSomething()
> DoSomething(Something)
> Loop While (Something < 5)
> "Thomas" <replyingroup@.anywhere.com> wrote in message news:OWtdcLSRFHA.235
6@.TK2MSFTNGP14.phx.gbl...
>|||Just an example off the top of my head, can't say it makes any sense to =
me either, the main thing I wanted was a loop that runs at least once.
"KH" <KH@.discussions.microsoft.com> wrote in message =
news:0DF4A1CF-94E9-4839-8624-DE769BCAE747@.microsoft.com...
> That's an odd design pattern - declaring the variable for the exit =
condition=20
> within the loop. If both GetSomething() and DoSomething(Something) are =

> deterministic then the condition will either always be false in which =
case=20
> there's no reason to have it, or always be true in which case the loop =
will=20
> never exit.=20
>=20
>=20
> "Raterus" wrote:
>=20
loop. What I'm trying to avoid is having to set "Something" before the =
loop, and also in the loop, repeating the exact same syntax. A normal =
While loop won't work without duplicating the code from within the loop.
news:OWtdcLSRFHA.2356@.TK2MSFTNGP14.phx.gbl...
any syntax=20
loop once,=20
would look=20|||Thanks, I had always "hacked" around it using methods like this. Just =
wanted to make sure I wasn't missing anything syntactically.
"KH" <KH@.discussions.microsoft.com> wrote in message =
news:0C77E8A0-3E6D-4C1D-A339-2040364DE56B@.microsoft.com...
> That's not the same as a do/while loop - with a do/while loop (as =
shown, or=20
> in the C languages) the code in the loop runs at least once. A couple =
options:
>=20
> 1. Change your condition so it will always be true the first time; to=20
> continue your example:
> WHILE (something < 6) BEGIN ... END
>=20
> 2. Move the condition to an IF statement at the end of the loop:
> WHILE (1=3D1)
> BEGIN
> -- code...
> IF (something =3D 5) BREAK
> END
>=20
> 3. Use a GOTO statement:
>=20
> _LOOP:
> -- ... CODE
> IF (something < 5) GOTO _LOOP
>=20
>=20
>=20
> "Thomas" wrote:
>=20
any syntax=20
loop once,=20
look=20|||Declare @.Done TinyInt Set @.Done = 0
While @.Done = 0 Begin
-- Do some work here
If GetSomething() = 'done' Set @.Done =1
End
"Raterus" wrote:

> Just an example off the top of my head, can't say it makes any sense to me
either, the main thing I wanted was a loop that runs at least once.
> "KH" <KH@.discussions.microsoft.com> wrote in message news:0DF4A1CF-94E9-48
39-8624-DE769BCAE747@.microsoft.com...
ing the code from within the loop.
>