Showing posts with label queries. Show all posts
Showing posts with label queries. Show all posts

Friday, March 30, 2012

run-time changeable queries

I need to extract and store a value from a table (or from a MS Access file with OpenDataSource) which is not always the same and it is therefore stored in the @.openfile variable. Something like this:
...
declare @.standardselect nvarchar(4000)
declare @.value int
select @.standardSelect='select top 1 @.value=val from ' + @.openfile
exec (@.standardSelect)
...

It obviously doesn't work because the variable @.value is not declared within the sql string.
However, since @.openfile is always different, I need to pass it through a string and the only way I know is within a variable. If I declare @.value inside the @.standardselect it is not accessible to the rest of the procedure, which is not acceptable for me.

Any suggestions?I have solved it using a temporary table, rather than a variable, where to store the value val. But if you have a better idea...|||

You can use EXEC statement

@.sSQL = 'select...from ' + @.tablename + ' where ...'
Exec @.sSQL

However this is a bad practice.

|||Andranik Khachatryan, I guess you haven't read the code in my first message?

Andranik Khachatryan wrote:

You can use EXEC statement

@.sSQL = 'select...from ' + @.tablename + ' where ...'
Exec @.sSQL

However this is a bad practice.

|||

Oops sorry :)

My bad, I am a bit careless today.

|||

You could use sp_executesql with output parameters to do this.

Declare @.StandardSelect nvarchar(4000)
Declare @.Value Int

Select @.StandardSelect = 'Select top 1 @.Value=Id From ' + @.OpenFile
exec sp_executesql @.StandardSelect, N'@.Value int output', @.value OUTPUT

Select @.value

|||

You don't really need dynamic SQL for doing this. You can do below instead:

declare @.source varchar(30)

-- ... initialize based on whether you want to query table or Access

set @.source =

declare @.value int

set @.value = (

select top 1 val from (

select val from your_table where @.source = 'table'

union all

select val from opendatasource(...) where @.source = 'access'

) as t

order by ...

)

Wednesday, March 21, 2012

running status for jobs

Hello all,

I would like to know how to how to know through sql queries if a job
that was processed is still running...

I tried to use msdb..systasks but it doesn't seem to help (status not
running and status running only).

Thanks in advance for your answer.

AndyHi

You could use "master.dbo.xp_sqlagent_enum_jobs"
--

Jack Vamvas
___________________________________
Need an IT job? http://www.ITjobfeed.com/SQL
<Andy.H.Kwok@.gmail.comwrote in message
news:1190367292.261350.224760@.r29g2000hsg.googlegr oups.com...

Quote:

Originally Posted by

Hello all,
>
I would like to know how to how to know through sql queries if a job
that was processed is still running...
>
I tried to use msdb..systasks but it doesn't seem to help (status not
running and status running only).
>
Thanks in advance for your answer.
>
Andy
>

sql

Running SqlAgent on a different processor

I have a machine with dual processor installed. I want sqlagent to be run on
the second processor while my normal queries run on the first processor is i
t
viable"Genius" <Genius@.discussions.microsoft.com> wrote in message
news:2D2F162B-F706-46BE-85E2-63D3BA9AF516@.microsoft.com...
> I have a machine with dual processor installed. I want sqlagent to be run
on
> the second processor while my normal queries run on the first processor is
it
> viable
>
As far as I know this is not possible... in almost every instance you're
better off letting the server OS manage the use context switching of
multi-processor machines.
Steve|||All the Whitepaper studies I've seen show this to be true: that the OS is
far more capable of handling the scheduling work through the SMP processors
than attempting to manually affinitizing the process yourself.
That being said, yes you can affinitize processes. You can manually set the
process affinity to a currently running executable through task manager. If
you want this to be permanent, you must create a registry key in the
Services Key for that process. There is a tool you can download from
Microsoft that will handle the details for you. Search for Process Affinity
to find it.
Sincerely,
Anthony Thomas
"Steve Thompson" <stevethompson@.nomail.please> wrote in message
news:O896ydn8EHA.208@.TK2MSFTNGP12.phx.gbl...
"Genius" <Genius@.discussions.microsoft.com> wrote in message
news:2D2F162B-F706-46BE-85E2-63D3BA9AF516@.microsoft.com...
> I have a machine with dual processor installed. I want sqlagent to be run
on
> the second processor while my normal queries run on the first processor is
it
> viable
>
As far as I know this is not possible... in almost every instance you're
better off letting the server OS manage the use context switching of
multi-processor machines.
Steve

Running SqlAgent on a different processor

I have a machine with dual processor installed. I want sqlagent to be run on
the second processor while my normal queries run on the first processor is it
viable
"Genius" <Genius@.discussions.microsoft.com> wrote in message
news:2D2F162B-F706-46BE-85E2-63D3BA9AF516@.microsoft.com...
> I have a machine with dual processor installed. I want sqlagent to be run
on
> the second processor while my normal queries run on the first processor is
it
> viable
>
As far as I know this is not possible... in almost every instance you're
better off letting the server OS manage the use context switching of
multi-processor machines.
Steve
|||All the Whitepaper studies I've seen show this to be true: that the OS is
far more capable of handling the scheduling work through the SMP processors
than attempting to manually affinitizing the process yourself.
That being said, yes you can affinitize processes. You can manually set the
process affinity to a currently running executable through task manager. If
you want this to be permanent, you must create a registry key in the
Services Key for that process. There is a tool you can download from
Microsoft that will handle the details for you. Search for Process Affinity
to find it.
Sincerely,
Anthony Thomas

"Steve Thompson" <stevethompson@.nomail.please> wrote in message
news:O896ydn8EHA.208@.TK2MSFTNGP12.phx.gbl...
"Genius" <Genius@.discussions.microsoft.com> wrote in message
news:2D2F162B-F706-46BE-85E2-63D3BA9AF516@.microsoft.com...
> I have a machine with dual processor installed. I want sqlagent to be run
on
> the second processor while my normal queries run on the first processor is
it
> viable
>
As far as I know this is not possible... in almost every instance you're
better off letting the server OS manage the use context switching of
multi-processor machines.
Steve
sql

Running SqlAgent on a different processor

I have a machine with dual processor installed. I want sqlagent to be run on
the second processor while my normal queries run on the first processor is it
viable"Genius" <Genius@.discussions.microsoft.com> wrote in message
news:2D2F162B-F706-46BE-85E2-63D3BA9AF516@.microsoft.com...
> I have a machine with dual processor installed. I want sqlagent to be run
on
> the second processor while my normal queries run on the first processor is
it
> viable
>
As far as I know this is not possible... in almost every instance you're
better off letting the server OS manage the use context switching of
multi-processor machines.
Steve|||All the Whitepaper studies I've seen show this to be true: that the OS is
far more capable of handling the scheduling work through the SMP processors
than attempting to manually affinitizing the process yourself.
That being said, yes you can affinitize processes. You can manually set the
process affinity to a currently running executable through task manager. If
you want this to be permanent, you must create a registry key in the
Services Key for that process. There is a tool you can download from
Microsoft that will handle the details for you. Search for Process Affinity
to find it.
Sincerely,
Anthony Thomas
"Steve Thompson" <stevethompson@.nomail.please> wrote in message
news:O896ydn8EHA.208@.TK2MSFTNGP12.phx.gbl...
"Genius" <Genius@.discussions.microsoft.com> wrote in message
news:2D2F162B-F706-46BE-85E2-63D3BA9AF516@.microsoft.com...
> I have a machine with dual processor installed. I want sqlagent to be run
on
> the second processor while my normal queries run on the first processor is
it
> viable
>
As far as I know this is not possible... in almost every instance you're
better off letting the server OS manage the use context switching of
multi-processor machines.
Steve