Wednesday, March 28, 2012
Precompiling checking problem
the commands all execute fine if i execute them one at a time, but when i
try to create a sp out of the script, it fails
problem... my sp adds a coulmn to a table in the begining, does some
processing and uses that column, then drops it.
the process that saves the sp tries to validate each command individually
instead of as a progression so obviously a select statement with the new
column is not valid on its own and it wont process the script.
is their any directive in QA that can turn off this checking?
i have a work around, build the query dynamically, but this is a pain as far
as im concerned.
any suggestions?
not sure I understand completely, BUT I think your problem may be resolved
by placing GO statements after each step in the sproc.
try that (if you havent already) and script the thing out and paste it in
here if that still does not work..
that we we can all have a look at it and get through the guesswork.
Greg Jackson
PDX, Oregon
|||example:
table1 has column1, column2, column3
i create a script to make a stored procedure in query analyzer:
create proc test1 as
alter table to add column4
update table1 to set column4 = to something
update table1 to set other columns to something
alter table to drop column4
go
1) execute each internal line seperately, each runs without error
2) execute script to create the proc, ERROR cause it checks each command
before creating the proc and since the second line sets column4 to
something, and column4 is not there right now, its an invalid command and
the proc isnt created
3) cant put go's between the commands in a stored procedure and even if you
could, the system still wont save the procedure cause line2 is still invalid
at this moment in time.
|||Claude Hebert wrote:
> example:
> table1 has column1, column2, column3
> i create a script to make a stored procedure in query analyzer:
> create proc test1 as
> alter table to add column4
> update table1 to set column4 = to something
> update table1 to set other columns to something
> alter table to drop column4
>
Without trying to understand what you are doing, the problem is that
each of those statements must be in its own batch. You have to use
dynamic sql to do what you want:
create table dbo.test1 (col1 int)
go
insert into dbo.test1 values (1)
create proc dbo.test2 as
begin
EXEC ('alter table dbo.test1 add column4 int')
select * from dbo.test1
EXEC ('update dbo.test1 set column4 = 5')
select * from dbo.test1
EXEC ('alter table dbo.test1 drop column column4')
select * from dbo.test1
end
go
exec test2
drop proc dbo.test2
create table dbo.test1
David Gugick
Imceda Software
www.imceda.com
|||i know that works, and this is a very simple case...
because of the size of our project, the number of procedures, the number of
lines in those procedures that would have to be moved into EXEC statements,
i was trying to find another way...
i was just hopping there was a set something that i could do in QA to allow
the code to run without all the EXEC's
im guessing at this point, the answer is NO
|||Hi Greg
GO is a batch separator for the client, it is not a SQL statement. GO tells
the CLIENT to send a set of commands to SQL Server separately (that is what
a batch is).
GO is not possible inside a stored procedure, which always executes within a
single batch. In fact, if you are trying to create a stored proc in the
Query Analyzer, as soon as a GO is entered, that is the end of the
procedure.
HTH
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"pdxJaxon" <GregoryAJackson@.Hotmail.com> wrote in message
news:eG51le%23VFHA.2616@.TK2MSFTNGP14.phx.gbl...
> not sure I understand completely, BUT I think your problem may be resolved
> by placing GO statements after each step in the sproc.
> try that (if you havent already) and script the thing out and paste it in
> here if that still does not work..
> that we we can all have a look at it and get through the guesswork.
>
> Greg Jackson
> PDX, Oregon
>
|||yep my bad.
I didnt read carefully enough. I though he was talking about a SQL Script.
GAJ
Precision Problem
I can't seem to get a stored procedure to return decimal places. Here are the steps to re-create the problem:
--first create the following procedure
CREATE PROCEDURE test_precision
AS
BEGIN
RETURN 5.2
END
--then run the following code
DECLARE @.x DECIMAL(18,2)
EXECUTE @.x = test_precision
SELECT @.x
I would like this code to return 5.20, but instead it returns 5.00. Any assistance would be greatly appreciated. Thanks.if you are using SQL 2005 that is the problem. Your stored Procedure would work correctly in SQL 2000.
The work around
declare @.x FLOAT(18,2)
give that a try.|||ooops!! allow me to take that back - wrong thought process. sorry.
you need to edit your proc to read 5.20sql
Monday, March 26, 2012
Prbblems with a Process.
Today i want to execute the same process and it takes more than two
hours and the process doesnt finish.
I restart the server twice, and the problem persist.
What do you recommend to me to check and found the reason that the
process take more time.
Thanks a lot for your help!.
*** Sent via Developersdex http://www.codecomments.com ***Have you tried reindexing the underlying tables or running an UPDATE
STATISTICS on them? That might solve your issue. Do you have regular
maintenance routines setup for this server?
Also, check the execution plan and see if you see anything out of the
ordinary.
MeanOldDBA
derrickleggett@.hotmail.com
http://weblogs.sqlteam.com/derrickl
When life gives you a lemon, fire the DBA.
"MariaGuzman" wrote:
> Hi, i have a store procedure that takes about 20 minutes to execute.
> Today i want to execute the same process and it takes more than two
> hours and the process doesn4t finish.
> I restart the server twice, and the problem persist.
> What do you recommend to me to check and found the reason that the
> process take more time.
> Thanks a lot for your help!.
> *** Sent via Developersdex http://www.codecomments.com ***
>|||Hi Maria,
Do u have indexes created on that table.Try reindexing.
If the problem persists just recreate ur stored procedure.
Run the Profilor and see what is happening at the back.
or Enable C2 auditing feature to trace all the activities.
HTH
from
Doller|||In addition to checking the execution plan, also blocking can be the cause.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"MariaGuzman" <marisa@.devdex.com> wrote in message news:eXUUOnsyFHA.3588@.tk2msftngp13.phx.gb
l...
> Hi, i have a store procedure that takes about 20 minutes to execute.
> Today i want to execute the same process and it takes more than two
> hours and the process doesnt finish.
> I restart the server twice, and the problem persist.
> What do you recommend to me to check and found the reason that the
> process take more time.
> Thanks a lot for your help!.
> *** Sent via Developersdex http://www.codecomments.com ***
Prbblems with a Process.
Today i want to execute the same process and it takes more than two
hours and the process doesnt finish.
I restart the server twice, and the problem persist.
What do you recommend to me to check and found the reason that the
process take more time.
Thanks a lot for your help!.
*** Sent via Developersdex http://www.codecomments.com ***
Have you tried reindexing the underlying tables or running an UPDATE
STATISTICS on them? That might solve your issue. Do you have regular
maintenance routines setup for this server?
Also, check the execution plan and see if you see anything out of the
ordinary.
MeanOldDBA
derrickleggett@.hotmail.com
http://weblogs.sqlteam.com/derrickl
When life gives you a lemon, fire the DBA.
"MariaGuzman" wrote:
> Hi, i have a store procedure that takes about 20 minutes to execute.
> Today i want to execute the same process and it takes more than two
> hours and the process doesn4t finish.
> I restart the server twice, and the problem persist.
> What do you recommend to me to check and found the reason that the
> process take more time.
> Thanks a lot for your help!.
> *** Sent via Developersdex http://www.codecomments.com ***
>
|||Hi Maria,
Do u have indexes created on that table.Try reindexing.
If the problem persists just recreate ur stored procedure.
Run the Profilor and see what is happening at the back.
or Enable C2 auditing feature to trace all the activities.
HTH
from
Doller
|||In addition to checking the execution plan, also blocking can be the cause.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"MariaGuzman" <marisa@.devdex.com> wrote in message news:eXUUOnsyFHA.3588@.tk2msftngp13.phx.gbl...
> Hi, i have a store procedure that takes about 20 minutes to execute.
> Today i want to execute the same process and it takes more than two
> hours and the process doesnt finish.
> I restart the server twice, and the problem persist.
> What do you recommend to me to check and found the reason that the
> process take more time.
> Thanks a lot for your help!.
> *** Sent via Developersdex http://www.codecomments.com ***
sql
Prbblems with a Process.
Today i want to execute the same process and it takes more than two
hours and the process doesn´t finish.
I restart the server twice, and the problem persist.
What do you recommend to me to check and found the reason that the
process take more time.
Thanks a lot for your help!.
*** Sent via Developersdex http://www.developersdex.com ***Have you tried reindexing the underlying tables or running an UPDATE
STATISTICS on them? That might solve your issue. Do you have regular
maintenance routines setup for this server?
Also, check the execution plan and see if you see anything out of the
ordinary.
--
MeanOldDBA
derrickleggett@.hotmail.com
http://weblogs.sqlteam.com/derrickl
When life gives you a lemon, fire the DBA.
"MariaGuzman" wrote:
> Hi, i have a store procedure that takes about 20 minutes to execute.
> Today i want to execute the same process and it takes more than two
> hours and the process doesn4t finish.
> I restart the server twice, and the problem persist.
> What do you recommend to me to check and found the reason that the
> process take more time.
> Thanks a lot for your help!.
> *** Sent via Developersdex http://www.developersdex.com ***
>|||Hi Maria,
Do u have indexes created on that table.Try reindexing.
If the problem persists just recreate ur stored procedure.
Run the Profilor and see what is happening at the back.
or Enable C2 auditing feature to trace all the activities.
HTH
from
Doller|||In addition to checking the execution plan, also blocking can be the cause.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"MariaGuzman" <marisa@.devdex.com> wrote in message news:eXUUOnsyFHA.3588@.tk2msftngp13.phx.gbl...
> Hi, i have a store procedure that takes about 20 minutes to execute.
> Today i want to execute the same process and it takes more than two
> hours and the process doesn´t finish.
> I restart the server twice, and the problem persist.
> What do you recommend to me to check and found the reason that the
> process take more time.
> Thanks a lot for your help!.
> *** Sent via Developersdex http://www.developersdex.com ***
Friday, March 23, 2012
POWER function
Hello,
I'm trying to follow a specification here:
W1 = (W0^0.333 + G * D/1000)^3 (the ^ symbol means 'to the power')
In my stored procedure I have used the following test data with unexpected results. Can anyone tell me if I'm using POWER properly?
@.Value = POWER(((POWER(150,(1/3))+ 2)* 10/1000),3)
Thanks
I think you are adding parentheses that are forcing a different order of arguments than the original. Here is what the original equation looks like with parentheses:
W1 = ( W0^(1/3) + ( G * D/1000) )^3
Your equation is written like this:
Val = ( (150^(1/3) + 2) * 10/1000 ) ^3|||Thanks Darrell, you're right about the parentheses. However, even with the correction and replacing '1/3' with 0.3333 (which makes a difference) - the results are still out - we expect the @.Value to be 150+ and it's only 125+. But you think the nested POWER function is OK? Or should I do this in 2 seperate statements?|||
Do you have to multiply G with D before dividing it by 1000? Maybe you miss a parenthesis with G*D.
W1 = ( W0^(1/3) + ((G * D)/1000) )^3
|||Thanks, but tried that with no improvement. I've read elsewhere that "SQL server does not have a datatype for fractions and instead uses an approximate datatype such as float, where rounding will occur. Float has a maximum precision of 15 digits." Does this mean that trying to get a cube root with POWER is indeterminate? Has anyone by any chance written a function for getting cube roots? At the moment POWER is giving me 5 as a cube root of 150 - which is way out.
set
@.value=POWER(150,1.00/3.00)|||Here are the relevant links and by Microsoft docs there is no indication the POWER function in SQL Server is none deterministic and yes it is FLOAT dependent. The links below will take you in the right direction. Hope this helps.
http://msdn2.microsoft.com/en-us/library/ms173773.aspx
http://msdn2.microsoft.com/en-us/library/ms174276.aspx
http://msdn2.microsoft.com/en-us/library/ms177516.aspx
Caddre,
I'm having a 'duh' moment! Thanks for that- making the value being acted on convertible to float (150.00 instead of 150) gave the result we were looking for.
|||
ashaig:
Caddre,
I'm having a 'duh' moment! Thanks for that- making the value being acted on convertible to float (150.00 instead of 150) gave the result we were looking for.
I am glad I could help and you are not alone most people don't know that most are FLOAT dependent.
|||Try this one, you can always change the precision to max.
POWER(CONVERT(float, 150), 0.333)
Wednesday, March 21, 2012
Posting XMLA to AS from java without msmdpump.dll
Posting the request via HttpURLConnection as below works.
url = new URL("http://localhost//olap/
HttpURLConnection con = (HttpURLConnection) url.openConnection();
The question is I'd prefer not to have to require IIS plus the pump to be running on the AS server(msmdpump.dll). We know MS code is sending XMLA to the AS Database.
Why can we not use the same channel? It may not be http but I do not care. I'd rather have minimum stuff to do on the server.
Thanks in advance
Zub
I'd say in this stiuation you are probably better off using HTTP. On windows machine you can use naitive AS client : ADOMD.NET or AS OLEDB, and establish connection using TCP/IP , but coming from outside you will face quite a few problems. Configuring virtual direcory compared to ... for instance trying to figure out how to authenticate your non-windows user if by far easier task.
Hope that helps.
Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
POSTING IT AGAIN TO RESOLVE THE ERROR
When i use the "sp_copysubscription" procedure, i am getting the following
error.
"Server: Msg 21236, Level 16, State 1, Procedure sp_copysubscription, Line
64
The subscription(s) to Publisher 'CNS_SQL1' does not allow subscription copy
or it has not been synchronized.".
My subscription datbabase contains only PULL subscription.It worked
previously and now started to give the above error.
Any help would be appreciated?
NOTE:
I do have anonymous pull subscription.
Copy subscription was working earlier and it is not now.
How to enable my publication for the copy subscription option?
Thanks,
Vijay
just for kicks, lets try this, go to your subscription database which you
pulled using anonymous authentication. Run the merge agent until it stops or
stop and start it until it goes idle, then stop it again.
Then start up profiler to trace the commands.
Then right click on your database in EM, select all tasks, and copy
subscription database. Does it work now? Does profiler give a different set
of parameters than what you are using?
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Vijay" <vijay@.infosysusa.com> wrote in message
news:%23L$h4jWNFHA.1172@.TK2MSFTNGP12.phx.gbl...
> Hi,
> When i use the "sp_copysubscription" procedure, i am getting the following
> error.
> "Server: Msg 21236, Level 16, State 1, Procedure sp_copysubscription, Line
> 64
> The subscription(s) to Publisher 'CNS_SQL1' does not allow subscription
copy
> or it has not been synchronized.".
> My subscription datbabase contains only PULL subscription.It worked
> previously and now started to give the above error.
> Any help would be appreciated?
> NOTE:
> I do have anonymous pull subscription.
> Copy subscription was working earlier and it is not now.
> How to enable my publication for the copy subscription option?
> Thanks,
> Vijay
>
>
|||No, it doesn't work. I couldn't find any difference in the trace also.
..
"Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
news:ewB10weNFHA.2136@.TK2MSFTNGP14.phx.gbl...
> just for kicks, lets try this, go to your subscription database which you
> pulled using anonymous authentication. Run the merge agent until it stops
or
> stop and start it until it goes idle, then stop it again.
> Then start up profiler to trace the commands.
> Then right click on your database in EM, select all tasks, and copy
> subscription database. Does it work now? Does profiler give a different
set[vbcol=seagreen]
> of parameters than what you are using?
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
> "Vijay" <vijay@.infosysusa.com> wrote in message
> news:%23L$h4jWNFHA.1172@.TK2MSFTNGP12.phx.gbl...
following[vbcol=seagreen]
Line
> copy
>
|||what happens if you reinitialize, and resync. Can you do it now?
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Vijay" <vijay@.infosysusa.com> wrote in message
news:edD4fDhNFHA.3788@.tk2msftngp13.phx.gbl...[vbcol=seagreen]
> No, it doesn't work. I couldn't find any difference in the trace also.
> .
> "Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
> news:ewB10weNFHA.2136@.TK2MSFTNGP14.phx.gbl...
you[vbcol=seagreen]
stops[vbcol=seagreen]
> or
> set
> following
> Line
subscription
>
|||Hi,
I reinitialized and resync it. It doesn't help.
Any other ideas?
Thanks,
Vijay
"Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
news:OxnXX2iNFHA.2556@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> what happens if you reinitialize, and resync. Can you do it now?
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
> "Vijay" <vijay@.infosysusa.com> wrote in message
> news:edD4fDhNFHA.3788@.tk2msftngp13.phx.gbl...
> you
> stops
different[vbcol=seagreen]
sp_copysubscription,
> subscription
>
sql
Postage Calculation goes where?
Should I have the stored procedure calculate the postage and packing for the order or should I wait till the order details are returned to the asp.net code, do some calculations, and then update the order?
Having this code in the asp.net page would not only require a trip to the server to do the update but also a trip to retrieve p&p information used for the calculations. These extra trips are my concern.
Any thoughts?::These extra trips are my concern.
Why? Are you working for Amazon?
How many hundred CHECKOUTS do you have per minute?
IMHO this is a non-issue, at least with some caching.
Monday, March 12, 2012
Possible?: Count(*) returned by EXEC
I have a stored procdure which does a select and returns the records
directly -i.e. Not in output parameters e.g:
CREATE PROCEDURE up_SelectRecs(@.ProductName nvarchar(30)) AS
SELECT *
FROM MyTable
WHERE [Name]=@.ProductName
In another stored procedure I need to do the following:
SELECT COUNT(*)
FROM MyTable
WHERE [Name]=@.ProductName
As the select queries are actually a lot more complex that this, I'd
rather not duplicate the select code in 2 sp's to save the maintenance
effort - I'm looking for a way to execute the first procedure from the
second and just count the records returned - something like:
SELECT Count(*)
FROM EXEC up_SelectRecs @.ProductName
Any way to achieve this?
Thanks all
--James"James" <Jamesmitchard@.yahoo.co.uk> wrote in message
news:19d01a84.0501261535.1d7c6dd7@.posting.google.c om...
> Hi all,
> I have a stored procdure which does a select and returns the records
> directly -i.e. Not in output parameters e.g:
> CREATE PROCEDURE up_SelectRecs(@.ProductName nvarchar(30)) AS
> SELECT *
> FROM MyTable
> WHERE [Name]=@.ProductName
> In another stored procedure I need to do the following:
> SELECT COUNT(*)
> FROM MyTable
> WHERE [Name]=@.ProductName
> As the select queries are actually a lot more complex that this, I'd
> rather not duplicate the select code in 2 sp's to save the maintenance
> effort - I'm looking for a way to execute the first procedure from the
> second and just count the records returned - something like:
> SELECT Count(*)
> FROM EXEC up_SelectRecs @.ProductName
> Any way to achieve this?
> Thanks all
> --James
See here:
http://www.sommarskog.se/share_data.html
If you have SQL 2000 (you didn't mention which version you have), a
table-valued UDF would probably work well in your case:
select * from dbo.MyFunc(@.ProductName)
select count(*) from dbo.MyFunc(@.ProductName)
Simon
Possible to specifying a list as a parameter to a stored procedure ?
SELECT tblAccount.txtName FROM tblAccount WHERE (tblAccount.intCurrencyId IN(1, 5, 7))
The list could contain a single value or upto 20 values. Is it possible to pass the currency list (i.e "1, 5, 7, ...") as a parameter to the stored procedure?
Any help much appreciated!The answer is, "maybe".
It depends on your needs for performance. Please take a look at this discussion for more details.
http://www.sql-server-performance.com/forum/topic.asp?TOPIC_ID=15403
Essentially, if you pass the list as a comma delimited string, then you will either need to parse it inside the query or use it in a dynamic SQL query within the SP. Your other choice is to take all 20 objects as single parameters to your SP. Your IN statement would then be a large set of OR statements for each of the 20 items.
I hope this helps,
CC|||I have to write a lot of stored procedures for reports. I always declare my parameters like
level1 varchar(255)
I then look at the incoming value. I use charindex to find ';' or ',' If I find either I know I have to use "in" in the where clause and format the values correctly.
IF CHARINDEX(';',@.LEVEL1)>0
BEGIN
SET @.LEVEL1=REPLACE('('+''''+REPLACE(@.LEVEL1,';',''''+ ','+'''')+''''+')',' ','')
END
If it is prompt is equal to '%' for all I make my where clause a like, if it is a single value I use equal. The trick to making this so flexible is to use dynamic sql. If you don't know what the parameter will be before hand it seems to be the best way.
' AND ISNULL(T1.DIVISION,'+''''+'NONE'+''''+')' +
case when CHARINDEX(',',@.LEVEL1)>0 then 'in '+@.LEVEL1
else
CASE @.LEVEL1 when '%' THEN ' LIKE '+''''+@.LEVEL1+''''+'+'+''''+'%'+''''
ELSE '='+''''+@.LEVEL1+'''' END
END
Sorry for the formating. It looks better in the actual file|||Oh and I just realized something. If the incoming value is '%' then do not add a condition for it in the dynamic where clause. It makes zero sense to add anything to a where clause if you don't need to.
Friday, March 9, 2012
Possible to pass table as parametr to stored procedure??
after this i call to other stored procedure to which i want pass table as
parameter.
How can i do it '
Message posted via http://www.webservertalk.comNo there is not way without looping through a resultset and giving the
seperate fields as variables or as an "array".
http://vyaskn.tripod.com/passing_ar..._procedures.htm
But you could create a (gobal) temp table from another procedure and call
this temp table at the destination procedure.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"JB via webservertalk.com" <forum@.nospam.webservertalk.com> schrieb im Newsbeitrag
news:c902681f62414d1cb7c0a8dca5cea43e@.SQ
webservertalk.com...
> In one stored procedure i create temporary table and fill it with data,
> after this i call to other stored procedure to which i want pass table as
> parameter.
> How can i do it '
> --
> Message posted via http://www.webservertalk.com|||See if this helps: http://www.sommarskog.se/share_data.html
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"JB via webservertalk.com" <forum@.nospam.webservertalk.com> wrote in message
news:c902681f62414d1cb7c0a8dca5cea43e@.SQ
webservertalk.com...
> In one stored procedure i create temporary table and fill it with data,
> after this i call to other stored procedure to which i want pass table as
> parameter.
> How can i do it '
> --
> Message posted via http://www.webservertalk.com|||Hi
Or you can create a Table using the Table Data Type and pass that between
SP's.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:OJND4SbTFHA.2128@.TK2MSFTNGP15.phx.gbl...
> No there is not way without looping through a resultset and giving the
> seperate fields as variables or as an "array".
> http://vyaskn.tripod.com/passing_ar..._procedures.htm
>
> But you could create a (gobal) temp table from another procedure and call
> this temp table at the destination procedure.
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
>
> "JB via webservertalk.com" <forum@.nospam.webservertalk.com> schrieb im
> Newsbeitrag news:c902681f62414d1cb7c0a8dca5cea43e@.SQ
webservertalk.com...
>|||Thanks for replay.
In my sp i define:
DECLARE @.myTable TABLE(
[col1] [int] ,
[col2] [bit] ,
..........
..........
if i understand i can do the same and to declare as @.@.myTable
and from now i can use this tabel in all proc?
Message posted via http://www.webservertalk.com|||thanks however it not help me. (i've read it before).
Message posted via http://www.webservertalk.com|||can u give a sample? i don't really undersatand how to achieve it
Message posted via http://www.webservertalk.com|||You cannot pass a table variable as parameter to stored procedures. But if
you look at the article I posted in my previous post, you will find a way
out
--
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"JB via webservertalk.com" <forum@.webservertalk.com> wrote in message
news:053b03bed2fe474fb8510840a324d760@.SQ
webservertalk.com...
> can u give a sample? i don't really undersatand how to achieve it
> --
> Message posted via http://www.webservertalk.com|||O yes.. u r right my mistake, sorry
Thank u very much.
Message posted via http://www.webservertalk.com|||Hi
See if it helps you
Use Northwind
CREATE PROC mysp2
AS
SELECT * FROM #Test
GO
CREATE PROC mysp1--Main stored procedure
@.Ord INT
AS
CREATE TABLE #Test
(
cust CHAR(5)
)
INSERT INTO #Test SELECT Customerid FROM Orders WHERE OrderId=@.Ord
EXEC mysp2 --We will use the #Test temp table within mysp2
--Usage
EXEC mysp1 10248
DROP PROC mysp1,mysp2
"JB via webservertalk.com" <forum@.webservertalk.com> wrote in message
news:fcd2f7925c90404592916ac6c168bcc5@.SQ
webservertalk.com...
> thanks however it not help me. (i've read it before).
> --
> Message posted via http://www.webservertalk.com
Possible to make a procedure "sleep" or run periodically?
I would like to write a procedure that periodically checks some things in my
database, but I don't want them to suck up a lot of resources. If I could
write a procedure that runs in a loop with a 5 minute sleep command, that
would do it.
Or is this the wrong approach in SQL Server? I realize I could set up a
separate scheduled task that executes a procedure using ISQL. Is this a
better method?
Rick Harrison.I don't know enough about the particual need to know if there is a better
way or is this is a good way... I've done things like this in the past using
the WAITFOR command. You'll find info in BOL...
--
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"Rick Harrrison" <rick@.knowware.com> wrote in message
news:uGKLBEQxDHA.1060@.TK2MSFTNGP12.phx.gbl...
> Is it possible to put a "sleep" command in a stored procedure.
> I would like to write a procedure that periodically checks some things in
my
> database, but I don't want them to suck up a lot of resources. If I could
> write a procedure that runs in a loop with a 5 minute sleep command, that
> would do it.
> Or is this the wrong approach in SQL Server? I realize I could set up a
> separate scheduled task that executes a procedure using ISQL. Is this a
> better method?
> Rick Harrison.
>|||Use SQL Server Agent to schedule the stored procedure?
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Rick Harrrison" <rick@.knowware.com> wrote in message
news:uGKLBEQxDHA.1060@.TK2MSFTNGP12.phx.gbl...
> Is it possible to put a "sleep" command in a stored procedure.
> I would like to write a procedure that periodically checks some things in
my
> database, but I don't want them to suck up a lot of resources. If I could
> write a procedure that runs in a loop with a 5 minute sleep command, that
> would do it.
> Or is this the wrong approach in SQL Server? I realize I could set up a
> separate scheduled task that executes a procedure using ISQL. Is this a
> better method?
> Rick Harrison.
>|||Hi Rick,
Thank you for using MSDN Newsgroup! I think Aaron and Brian have point out ways to run the
stored procedure (SP) on a schedule basis.
Based on my experience, it's better to use scheduled job IF you want to run your SP in a 5
minutes loop (it does handle that gracefully). The WAITFOR statement is also a good method
to implement this, however, it can only work after a specified time interval has passed or a
specified time is reached, unless you use an explicit loop in your SP.
Additionally, the stored procedure will remain suspended until the WAITFOR completes, this
may affect the performance. However, it can easily be embedded in your script and is not
Agent related. So it depends on your scenario and the needs you want to meet.
Rick, does this answer your question? If there is anything more I can do to assist you, please
feel free to post it in the group.
Best regards,
Billy Yao
Microsoft Online Support
----
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only. Thanks.|||Thanks! WAITFOR is what I was looking for. I did searches using "sleep" and
"pause", but I didn't think of "wait" or "delay".
Rick.
"Brian Moran" <brian@.solidqualitylearning.com> wrote in message
news:Osu%23o1QxDHA.1680@.TK2MSFTNGP12.phx.gbl...
> I don't know enough about the particual need to know if there is a better
> way or is this is a good way... I've done things like this in the past
using
> the WAITFOR command. You'll find info in BOL...
> --
> Brian Moran
> Principal Mentor
> Solid Quality Learning
> SQL Server MVP
> http://www.solidqualitylearning.com
>
> "Rick Harrrison" <rick@.knowware.com> wrote in message
> news:uGKLBEQxDHA.1060@.TK2MSFTNGP12.phx.gbl...
> > Is it possible to put a "sleep" command in a stored procedure.
> >
> > I would like to write a procedure that periodically checks some things
in
> my
> > database, but I don't want them to suck up a lot of resources. If I
could
> > write a procedure that runs in a loop with a 5 minute sleep command,
that
> > would do it.
> >
> > Or is this the wrong approach in SQL Server? I realize I could set up a
> > separate scheduled task that executes a procedure using ISQL. Is this a
> > better method?
> >
> > Rick Harrison.
> >
> >
>|||Thanks! Somehow I had overlooked this feature. I knew it was possible to
schedule maintenance plans, which I do, but I didn't know you could run any
procedure on a schedule.
Rick.
"Aaron Bertrand - MVP" <aaron@.TRASHaspfaq.com> wrote in message
news:OEAHM7QxDHA.1088@.tk2msftngp13.phx.gbl...
> Use SQL Server Agent to schedule the stored procedure?
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.aspfaq.com/
>
>
> "Rick Harrrison" <rick@.knowware.com> wrote in message
> news:uGKLBEQxDHA.1060@.TK2MSFTNGP12.phx.gbl...
> > Is it possible to put a "sleep" command in a stored procedure.
> >
> > I would like to write a procedure that periodically checks some things
in
> my
> > database, but I don't want them to suck up a lot of resources. If I
could
> > write a procedure that runs in a loop with a 5 minute sleep command,
that
> > would do it.
> >
> > Or is this the wrong approach in SQL Server? I realize I could set up a
> > separate scheduled task that executes a procedure using ISQL. Is this a
> > better method?
> >
> > Rick Harrison.
> >
> >
>|||Both techniques will be useful for me. Thank you.
""Billy Yao [MSFT]"" <v-binyao@.online.microsoft.com> wrote in message
news:FTG3OcWxDHA.424@.cpmsftngxa07.phx.gbl...
> Hi Rick,
> Thank you for using MSDN Newsgroup! I think Aaron and Brian have point out
ways to run the
> stored procedure (SP) on a schedule basis.
> Based on my experience, it's better to use scheduled job IF you want to
run your SP in a 5
> minutes loop (it does handle that gracefully). The WAITFOR statement is
also a good method
> to implement this, however, it can only work after a specified time
interval has passed or a
> specified time is reached, unless you use an explicit loop in your SP.
> Additionally, the stored procedure will remain suspended until the WAITFOR
completes, this
> may affect the performance. However, it can easily be embedded in your
script and is not
> Agent related. So it depends on your scenario and the needs you want to
meet.
> Rick, does this answer your question? If there is anything more I can do
to assist you, please
> feel free to post it in the group.
> Best regards,
> Billy Yao
> Microsoft Online Support
> ----
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
> Please reply to newsgroups only. Thanks.
>
>
Possible to lock a row within a stored procedure in SQL Server 2000?
I have a table that holds pregenerated member IDs.
This table is used to assign an available member id to web site
visitors who choose to register with the site
So, conceptually the process has been, from the site (in ASP), to:
- select the top record from the members table where the assigned flag
= 0
- update the row with details about the new member and change the
assigned flag to 1
- return the selected member id to the web page
Now I'm dealing with the idea that there may be brief, high traffic
periods of registration, so I'm trying to build a method (stored
procedure?) that will ensure the same member id isn't returned by the
select statement if more than 1 request to register happens at the
same instant.
So, my question is, is there a way, once a record has been selected,
to exclude that record from other select requests, within the bounds
of a stored procedure?
ie:
- select statement is executed and row is instantly locked; any other
select statement running at that exact moment will receive a different
row returned and sill similarly lock it, ad nauseum for as many
simultaneous select statements as take place
- row is updated with details and flag is updated to indicate the
member id is no longer unassigned
- row is released for general purposes etc
If what I'm suggesting above isn't practical, can anyone help me
identify a different way of achieving the same result?
Any help immensely, immensely appreciated!
Much warmth,
MurrayM Wells <planetquirky@.planetthoughtful.org> wrote in message news:<j1o220p3uauokindou45q9l305eq8au783@.4ax.com>...
> Hi All,
> I have a table that holds pregenerated member IDs.
> This table is used to assign an available member id to web site
> visitors who choose to register with the site
> So, conceptually the process has been, from the site (in ASP), to:
> - select the top record from the members table where the assigned flag
> = 0
> - update the row with details about the new member and change the
> assigned flag to 1
> - return the selected member id to the web page
> Now I'm dealing with the idea that there may be brief, high traffic
> periods of registration, so I'm trying to build a method (stored
> procedure?) that will ensure the same member id isn't returned by the
> select statement if more than 1 request to register happens at the
> same instant.
> So, my question is, is there a way, once a record has been selected,
> to exclude that record from other select requests, within the bounds
> of a stored procedure?
> ie:
> - select statement is executed and row is instantly locked; any other
> select statement running at that exact moment will receive a different
> row returned and sill similarly lock it, ad nauseum for as many
> simultaneous select statements as take place
> - row is updated with details and flag is updated to indicate the
> member id is no longer unassigned
> - row is released for general purposes etc
> If what I'm suggesting above isn't practical, can anyone help me
> identify a different way of achieving the same result?
> Any help immensely, immensely appreciated!
> Much warmth,
> Murray
It's not clear from your description why you need to generate the IDs
in advance - a simpler approach might be to use an IDENTITY column,
and insert directly into the members table for a new registration. You
can then return the system-generated value to the client using
scope_identity(). This assumes, of course, that the membership ID is
simply a number, with no other meaning:
create table dbo.Members (
MemberID int identity(1,1) primary key,
FirstName varchar(50) not null,
LastName varchar(50) not null
)
go
insert into dbo.Members (FirstName, LastName)
values ('Murray', 'Wells')
select 'Your ID is: ' + cast(scope_identity() as char(2))
go
If you do need some control over the value of the membership ID, then
one of these approaches might be suitable:
http://groups.google.com/groups?q=s...uewin.ch&rnum=1
If this doesn't help, you may want to post the structure (CREATE
TABLE) of your members table, along with some sample data, and explain
exactly what you want to return to the client.
Simon|||On 4 Feb 2004 23:44:05 -0800, sql@.hayes.ch (Simon Hayes) wrote:
>M Wells <planetquirky@.planetthoughtful.org> wrote in message news:<j1o220p3uauokindou45q9l305eq8au783@.4ax.com>...
>> Hi All,
>>
[ here there be snippage ]
>It's not clear from your description why you need to generate the IDs
>in advance - a simpler approach might be to use an IDENTITY column,
>and insert directly into the members table for a new registration. You
>can then return the system-generated value to the client using
>scope_identity(). This assumes, of course, that the membership ID is
>simply a number, with no other meaning:
>create table dbo.Members (
>MemberID int identity(1,1) primary key,
>FirstName varchar(50) not null,
>LastName varchar(50) not null
>)
>go
>insert into dbo.Members (FirstName, LastName)
>values ('Murray', 'Wells')
>select 'Your ID is: ' + cast(scope_identity() as char(2))
>go
>If you do need some control over the value of the membership ID, then
>one of these approaches might be suitable:
>http://groups.google.com/groups?q=s...uewin.ch&rnum=1
>If this doesn't help, you may want to post the structure (CREATE
>TABLE) of your members table, along with some sample data, and explain
>exactly what you want to return to the client.
Hi Simon,
Thank you very much for your help with this!
Unfortunately, the need to use pre-generated member ids is a foregone
issue; it's not something I have any control over.
I looked at the two examples in the link you provided. The first makes
sense to me, but I can't formulate a query that makes it do exactly
what I want. And I don't yet know enough about locking in SQL Server
to know if the locking hint (UPDLOCK) does what I hope it will do.
To give you a little extra detail, my test table definition is:
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[tblmembers]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[tblmembers]
GO
CREATE TABLE [dbo].[tblmembers] (
[recid] [int] IDENTITY (1, 1) NOT NULL ,
[memid] [numeric](18, 0) NULL ,
[memname] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[mememail] [varchar] (255) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[activated] [bit] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblmembers] WITH NOCHECK ADD
CONSTRAINT [PK_tblmembers] PRIMARY KEY CLUSTERED
(
[recid]
) ON [PRIMARY]
GO
CREATE UNIQUE INDEX [IX_tblmembers_memid] ON
[dbo].[tblmembers]([memid]) ON [PRIMARY]
GO
INSERT tblmembers(recid,memid,memname,mememail,activated)
VALUES('1','1000001','John Smith','john@.smith.com','1')
INSERT tblmembers(recid,memid,memname,mememail,activated)
VALUES('2','1000002','Jen Smith','smith@.jen.com','1')
INSERT tblmembers(recid,memid,memname,mememail,activated)
VALUES('3','1000003','','','0')
INSERT tblmembers(recid,memid,memname,mememail,activated)
VALUES('4','1000004','','','0')
INSERT tblmembers(recid,memid,memname,mememail,activated)
VALUES('5','1000005','','','0')
So, the basic concept is that when a membership registration form is
submitted, I want to go and get the next unassigned member id
(activated=0) change the activated flag to 1 and update memname and
mememail fields with parameters passed from the form. I then need to
return the value in that record's memid field back to the confirmation
page.
I can do all of this, but I haven't been able to satisfy myself that
there won't be a problem if I get two simultaneous registration
requests.
In essence, I'm trying to figure a way, given the above sample data,
that if there are two simultaneous registration requests, one of them
is returned the row with the member id of 1000003 and one of them is
returned the row with the member id of 1000004. And, it probably goes
without saying, that if there are 3 simultaneous requests, the third
one would be returned the row with the member id of 1000005, and so
on. In other words, no two registrations should return the same member
id.
Given the examples you provided in the link, I was trying to do do
something similar to:
declare @.rowid numeric
UPDATE tblmembers set @.rowid=selmem.recid, activated = 1 where recid =
(SELECT TOP 1 recid from tblmembers where activated = 0) as selmem
return @.rowid
But, of course, this is invalid syntax, since it seems you can't
provide an alias to a subquery in an UPDATE statement as I have
attempoted to do above.
However, the concept was to perform the select and update in the same
statement, return the recid of the selected / updated row, and then
use that recid value to perform another update query etc to provide
the member name and email details.
I'm sorry if this only confuses matters, but my hope is that it
explains a little better what I'm hoping to achieve...
Thank you, again, for your help!
Much warmth,
Murray|||"M Wells" <planetquirky@.planetthoughtful.org> wrote in message
news:unq420d09pagnsd386892b6snq0vf03n8o@.4ax.com...
> On 4 Feb 2004 23:44:05 -0800, sql@.hayes.ch (Simon Hayes) wrote:
> >M Wells <planetquirky@.planetthoughtful.org> wrote in message
news:<j1o220p3uauokindou45q9l305eq8au783@.4ax.com>...
> >> Hi All,
> >>
> [ here there be snippage ]
> >It's not clear from your description why you need to generate the IDs
> >in advance - a simpler approach might be to use an IDENTITY column,
> >and insert directly into the members table for a new registration. You
> >can then return the system-generated value to the client using
> >scope_identity(). This assumes, of course, that the membership ID is
> >simply a number, with no other meaning:
> >create table dbo.Members (
> >MemberID int identity(1,1) primary key,
> >FirstName varchar(50) not null,
> >LastName varchar(50) not null
> >)
> >go
> >insert into dbo.Members (FirstName, LastName)
> >values ('Murray', 'Wells')
> >select 'Your ID is: ' + cast(scope_identity() as char(2))
> >go
> >If you do need some control over the value of the membership ID, then
> >one of these approaches might be suitable:
>http://groups.google.com/groups?q=s...l=en&lr=&ie=UTF
-8&oe=UTF-8&selm=40044e65%241_2%40news.bluewin.ch&rnum=1
> >If this doesn't help, you may want to post the structure (CREATE
> >TABLE) of your members table, along with some sample data, and explain
> >exactly what you want to return to the client.
>
> Hi Simon,
> Thank you very much for your help with this!
> Unfortunately, the need to use pre-generated member ids is a foregone
> issue; it's not something I have any control over.
> I looked at the two examples in the link you provided. The first makes
> sense to me, but I can't formulate a query that makes it do exactly
> what I want. And I don't yet know enough about locking in SQL Server
> to know if the locking hint (UPDLOCK) does what I hope it will do.
> To give you a little extra detail, my test table definition is:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[tblmembers]') and OBJECTPROPERTY(id,
> N'IsUserTable') = 1)
> drop table [dbo].[tblmembers]
> GO
> CREATE TABLE [dbo].[tblmembers] (
> [recid] [int] IDENTITY (1, 1) NOT NULL ,
> [memid] [numeric](18, 0) NULL ,
> [memname] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL ,
> [mememail] [varchar] (255) COLLATE
> SQL_Latin1_General_CP1_CI_AS NULL ,
> [activated] [bit] NULL
> ) ON [PRIMARY]
> GO
> ALTER TABLE [dbo].[tblmembers] WITH NOCHECK ADD
> CONSTRAINT [PK_tblmembers] PRIMARY KEY CLUSTERED
> (
> [recid]
> ) ON [PRIMARY]
> GO
> CREATE UNIQUE INDEX [IX_tblmembers_memid] ON
> [dbo].[tblmembers]([memid]) ON [PRIMARY]
> GO
>
> INSERT tblmembers(recid,memid,memname,mememail,activated)
> VALUES('1','1000001','John Smith','john@.smith.com','1')
> INSERT tblmembers(recid,memid,memname,mememail,activated)
> VALUES('2','1000002','Jen Smith','smith@.jen.com','1')
> INSERT tblmembers(recid,memid,memname,mememail,activated)
> VALUES('3','1000003','','','0')
> INSERT tblmembers(recid,memid,memname,mememail,activated)
> VALUES('4','1000004','','','0')
> INSERT tblmembers(recid,memid,memname,mememail,activated)
> VALUES('5','1000005','','','0')
> So, the basic concept is that when a membership registration form is
> submitted, I want to go and get the next unassigned member id
> (activated=0) change the activated flag to 1 and update memname and
> mememail fields with parameters passed from the form. I then need to
> return the value in that record's memid field back to the confirmation
> page.
> I can do all of this, but I haven't been able to satisfy myself that
> there won't be a problem if I get two simultaneous registration
> requests.
> In essence, I'm trying to figure a way, given the above sample data,
> that if there are two simultaneous registration requests, one of them
> is returned the row with the member id of 1000003 and one of them is
> returned the row with the member id of 1000004. And, it probably goes
> without saying, that if there are 3 simultaneous requests, the third
> one would be returned the row with the member id of 1000005, and so
> on. In other words, no two registrations should return the same member
> id.
> Given the examples you provided in the link, I was trying to do do
> something similar to:
> declare @.rowid numeric
> UPDATE tblmembers set @.rowid=selmem.recid, activated = 1 where recid =
> (SELECT TOP 1 recid from tblmembers where activated = 0) as selmem
> return @.rowid
> But, of course, this is invalid syntax, since it seems you can't
> provide an alias to a subquery in an UPDATE statement as I have
> attempoted to do above.
> However, the concept was to perform the select and update in the same
> statement, return the recid of the selected / updated row, and then
> use that recid value to perform another update query etc to provide
> the member name and email details.
> I'm sorry if this only confuses matters, but my hope is that it
> explains a little better what I'm hoping to achieve...
> Thank you, again, for your help!
> Much warmth,
> Murray
I think this is what you're looking for, assuming that your definition of
the 'next' row is the one with the lowest value for memid within the set of
rows which have an activated value of 0:
declare @.memid int,
@.memname varchar(50),
@.mememail varchar(255)
set @.memname = 'John Doe'
set @.mememail = 'john@.doe.com'
begin tran
select @.memid = min(memid)
from tblmembers with(updlock)
where activated = 0
update tblmembers
set activated = 1, memname = @.memname, mememail = @.mememail
where memid = @.memid
commit
select @.memid
Since you're returning the memid, but updating the other columns, you can't
use the UPDATE syntax I suggested in the link - you'll have to use the
locking hint, which needs to be inside a transaction. Note that I haven't
put any error handling in the code above, but you should definitely put it
in your real code. Here is a helpful resource:
http://www.sommarskog.se/error-handling-II.html
One other point is that having both the recid and memid columns seems to be
redundant - the natural primary key of the table appears to be memid (and
mememail may also be a candidate key), so it's not clear what purpose recid
serves, although I appreciate that you may not have complete control over
the schema, and that you may have simplified your real data here.
Simon|||[ here there be snippage ]
>I think this is what you're looking for, assuming that your definition of
>the 'next' row is the one with the lowest value for memid within the set of
>rows which have an activated value of 0:
>declare @.memid int,
> @.memname varchar(50),
> @.mememail varchar(255)
>set @.memname = 'John Doe'
>set @.mememail = 'john@.doe.com'
>begin tran
>select @.memid = min(memid)
>from tblmembers with(updlock)
>where activated = 0
>update tblmembers
>set activated = 1, memname = @.memname, mememail = @.mememail
>where memid = @.memid
>commit
>select @.memid
>
>Since you're returning the memid, but updating the other columns, you can't
>use the UPDATE syntax I suggested in the link - you'll have to use the
>locking hint, which needs to be inside a transaction. Note that I haven't
>put any error handling in the code above, but you should definitely put it
>in your real code. Here is a helpful resource:
>http://www.sommarskog.se/error-handling-II.html
>One other point is that having both the recid and memid columns seems to be
>redundant - the natural primary key of the table appears to be memid (and
>mememail may also be a candidate key), so it's not clear what purpose recid
>serves, although I appreciate that you may not have complete control over
>the schema, and that you may have simplified your real data here.
Hi Simon,
Thank you, thank you, thank you!
This seems to be doing exactly what I need it to do!
One question, though -- the min() function in the select statement
seems to slow the execution of the stored procedure considerably.
Is there anything wrong with simply using:
select Top 1 @.memid = memid from tblmembers with(updlock)
where activated = 0
My own testing _seems_ to establish this as being somewhat faster...
Again, thank you, thank you, thank you!
Much warmth,
Murray|||M Wells (planetquirky@.planetthoughtful.org) writes:
> This seems to be doing exactly what I need it to do!
> One question, though -- the min() function in the select statement
> seems to slow the execution of the stored procedure considerably.
> Is there anything wrong with simply using:
> select Top 1 @.memid = memid from tblmembers with(updlock)
> where activated = 0
> My own testing _seems_ to establish this as being somewhat faster...
Permit me to bump in here. I was about to suggest something last night
that was akin to what Simon proposed. But then I was struck of a sense
of doubt whether it would work or not. You see, the standard question
is about get the next value to insert. This pre-generated thing changes
the playing rules a bit. So I left your message unanswered and went to
bed.
Problem is that it is now about 24 hourse since I saw your question the
first time, which means that also today the bed is waiting for me. But
I can aleast provide a tip on how to test this. Add this statement to the
batch between the SELECT and the UPDATE:
WAITFOR DELAY '00:00:10'
Then run the batch from two different windows in Query Analyzer, and
see if you get the expected result.
Also, change the design of the table, so that the clustered index is
on memberid (you would do best in dropping recid; it serves no purpose),
and add a non-clustered index on activated. This may be good for
performance.
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||On Thu, 5 Feb 2004 23:46:45 +0000 (UTC), Erland Sommarskog
<sommar@.algonet.se> wrote:
>M Wells (planetquirky@.planetthoughtful.org) writes:
[ here there be snippage ]
>Permit me to bump in here. I was about to suggest something last night
>that was akin to what Simon proposed. But then I was struck of a sense
>of doubt whether it would work or not. You see, the standard question
>is about get the next value to insert. This pre-generated thing changes
>the playing rules a bit. So I left your message unanswered and went to
>bed.
(Laugh) Hi Erland -- you're more than welcome to bump in! Thank you
for adding your thoughts...
>Problem is that it is now about 24 hourse since I saw your question the
>first time, which means that also today the bed is waiting for me. But
>I can aleast provide a tip on how to test this. Add this statement to the
>batch between the SELECT and the UPDATE:
> WAITFOR DELAY '00:00:10'
>Then run the batch from two different windows in Query Analyzer, and
>see if you get the expected result.
Thank you for this suggestion -- I was wondering how to test if it
works, and it seems to do just that.
>Also, change the design of the table, so that the clustered index is
>on memberid (you would do best in dropping recid; it serves no purpose),
>and add a non-clustered index on activated. This may be good for
>performance.
The suggestion re the memberid field makes a lot of sense, but the
activated field is currently a BIT type. I was under the impression
you can't put indexes on BIT fields?
I've been wondering if there would be any benefit in changing this to
a TINYINT type so I can put an index on it. Storage isn't an issue,
however speed is.
Thanks, again, for your input -- and hope you got some good sleep.
Much warmth,
Murray|||M Wells (planetquirky@.planetthoughtful.org) writes:
> The suggestion re the memberid field makes a lot of sense, but the
> activated field is currently a BIT type. I was under the impression
> you can't put indexes on BIT fields?
Did you say which version of SQL Server you are using? It's correct that
in SQL7 and earlier, you cannot have bit column in indexes. However, in
SQL2000 this restriction is lifted.
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||On Fri, 6 Feb 2004 09:14:36 +0000 (UTC), Erland Sommarskog
<sommar@.algonet.se> wrote:
>M Wells (planetquirky@.planetthoughtful.org) writes:
>> The suggestion re the memberid field makes a lot of sense, but the
>> activated field is currently a BIT type. I was under the impression
>> you can't put indexes on BIT fields?
>Did you say which version of SQL Server you are using? It's correct that
>in SQL7 and earlier, you cannot have bit column in indexes. However, in
>SQL2000 this restriction is lifted.
Hi Erland,
Hmmm. I'm using SQL2000, but I don't see bit columns when I create
indexes using the Manage Indexes / Keys dialogue...
Do I need to create indexes for bit columns via SQL statements?
Much warmth,
Murray|||On Fri, 06 Feb 2004 14:09:45 GMT, M Wells
<planetquirky@.planetthoughtful.org> wrote:
>On Fri, 6 Feb 2004 09:14:36 +0000 (UTC), Erland Sommarskog
><sommar@.algonet.se> wrote:
[ here there be snippage ]
>Hi Erland,
>Hmmm. I'm using SQL2000, but I don't see bit columns when I create
>indexes using the Manage Indexes / Keys dialogue...
>Do I need to create indexes for bit columns via SQL statements?
Hi Erland,
No need to reply to the above -- I discovered that, yes, I can create
indexes on bit columns via SQL...
However, if I can be forgiven for one last question: given one or more
bit columns in the WHERE clause of a select statement, should I
explicitly CAST the value I'm looking for as a bit?
I came across this tip while surfing for information on bit columns,
but wasn't certain if this remained relevant fro SQL2K...
Many thanks to both you and Simon for all of your help!!
Much warmth,
Murray|||"M Wells" <planetquirky@.planetthoughtful.org> wrote in message
news:3sf720plrd91o572otgvri3pga73nrrej7@.4ax.com...
> On Fri, 06 Feb 2004 14:09:45 GMT, M Wells
> <planetquirky@.planetthoughtful.org> wrote:
> >On Fri, 6 Feb 2004 09:14:36 +0000 (UTC), Erland Sommarskog
> ><sommar@.algonet.se> wrote:
> [ here there be snippage ]
> >Hi Erland,
> >Hmmm. I'm using SQL2000, but I don't see bit columns when I create
> >indexes using the Manage Indexes / Keys dialogue...
> >Do I need to create indexes for bit columns via SQL statements?
> Hi Erland,
> No need to reply to the above -- I discovered that, yes, I can create
> indexes on bit columns via SQL...
> However, if I can be forgiven for one last question: given one or more
> bit columns in the WHERE clause of a select statement, should I
> explicitly CAST the value I'm looking for as a bit?
> I came across this tip while surfing for information on bit columns,
> but wasn't certain if this remained relevant fro SQL2K...
> Many thanks to both you and Simon for all of your help!!
> Much warmth,
> Murray
As far as I'm aware, there shouldn't be any need to explicitly CAST the
value to a bit, but I haven't used bit columns much, so I can't say for
sure.
To answer your previous question:
"Is there anything wrong with simply using:
select Top 1 @.memid = memid from tblmembers with(updlock)
where activated = 0"
The issue here is that TOP without ORDER BY doesn't really mean anything -
you will get one row returned, but in theory you could get any row where
activated = 0. In practice, if you have a clustered index on the table, then
you'll probably get rows back in the order of that index, but there's no
guarantee.
So if your business rule requires you to get the lowest possible memid, then
you would need to do this:
select Top 1 @.memid = memid
from tblmembers with(updlock)
where activated = 0
order by memid asc -- this defines what TOP means
This is effectively the same as my query, of course.
Simon|||M Wells (planetquirky@.planetthoughtful.org) writes:
> However, if I can be forgiven for one last question: given one or more
> bit columns in the WHERE clause of a select statement, should I
> explicitly CAST the value I'm looking for as a bit?
Yes.
This is because of the conversion rules in SQL Server. If you don't use
cast(), SQL Server will convert the bit column to integer. And whenever
a column is not used in its original shape, SQL Server can no longer
seek an index with this column.
It could still opt to scan the index, but it would have to scan all
pages for the index. However, for you repro, I got a table scan when
I did not use cast(). This may be due to the small size of the table.
However, when I used cast(), SQL Server used an Index Seek.
I think that even with a large members table, this method should be
really fast, although there is a cost for updating the index when you
activate the customer.
I also did some concurrency studies, and I feel fairly confident that
the method with UPDLOCK is safe.
Here is a repro, so you can see exactly what I ran:
CREATE TABLE [dbo].[tblmembers] (
[memid] [numeric](18, 0) NOT NULL ,
[memname] [varchar] (50) NULL,
[mememail] [varchar] (255) NULL ,
[activated] [bit] NOT NULL,
CONSTRAINT PK_tblmembers PRIMARY KEY CLUSTERED (memid)
)
GO
CREATE INDEX isactivated ON tblmembers(activated)
GO
INSERT tblmembers(memid,memname,mememail,activated)
VALUES('1000001','John Smith','john@.smith.com','1')
INSERT tblmembers(memid,memname,mememail,activated)
VALUES('1000002','Jen Smith','smith@.jen.com','1')
INSERT tblmembers(memid,memname,mememail,activated)
VALUES('1000003','','','0')
INSERT tblmembers(memid,memname,mememail,activated)
VALUES('1000004','','','0')
INSERT tblmembers(memid,memname,mememail,activated)
VALUES('1000005','','','0')
go
declare @.memid int,
@.memname varchar(50),
@.mememail varchar(255)
set @.memname = 'John Doe'
set @.mememail = 'john@.doe.com'
begin tran
select @.memid = min(memid)
from tblmembers with(updlock)
where activated = convert(bit, 0)
update tblmembers
set activated = 1, memname = @.memname, mememail = @.mememail
where memid = @.memid
commit
select @.memid
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||On Fri, 6 Feb 2004 23:06:17 +0000 (UTC), Erland Sommarskog
<sommar@.algonet.se> wrote:
[ here there be snippage ]
I just wanted to give a heartfelt thanks to both of you (Simon and
Erland) for all of your help with this.
I can't imagine a better testimony for the internet than the fact that
people like you two (and many others) go out of your way to share your
knowledge and expertise with a complete stranger who is struggling to
get something done.
Thank you both, again!
Much warmth,
Murray
http://www.planetthoughtful.org
Possible to Insert Records into ODBC Data Source from Stored Procedure?
to with an ODBC data source.
This is possible? If so, can you give me an example of how to connect?
Thanks,
MikeYes, it is possible, and there are numerous ways of connecting to an ODBC
data source. If you are using C#, take a look at class OdbcConnection in the
System.Data.Odbc namespace --
http://msdn2.microsoft.com/en-us/library/at2sk77y.aspx.
Linchi
"Mike" wrote:
> I would like to insert records into a non MS-SQL database that I can connect
> to with an ODBC data source.
> This is possible? If so, can you give me an example of how to connect?
> Thanks,
> Mike
>
>
Possible to have a sql query like this...
s = 32,45,2,13,4
in my SQL stored procedure... i want to do something like...
SELECT * FROM t1 WHERE t1.a IN s
I know that will not work with the comma character seperating each value...but is there a way to do it so that it work? i dont think there is...but i just want to make sure.This would work:
|||do you know why it has to be done this way? would it have worked if a delimiter was | rather than ,?
CREATE PROCEDURE GetProductsByID
(
@.s varchar(255)
)AS
DECLARE @.SELECT varchar(500)
SET @.SELECT = 'SELECT * FROM Products WHERE Products.ProductID IN (' + @.s + ')'EXEC(@.SELECT)
and say we have 33,23,45,65
will that also return rows wid ID's of 3, b/c of 33?
Wednesday, March 7, 2012
Possible to cache a dataset when testing in Visual Studio?
about 2 minutes to complete. It annoys me that when I change one little
formatting property in the layout, I have to wait for the stored procedure to
run again before I can see the results of my modification. I wish that I
could just cache the dataset created by this stored procedure when I'm
testing in Visual Studio and avoid rerunning it each time I change the
formatting. Can anyone tell me if this is possible? Thanks.It sounds like you did not install SP1 on your report designer machine. See
this section of the SP1 readme:
http://download.microsoft.com/download/7/f/b/7fb1a251-13ad-404c-a034-10d79ddaa510/SP1Readme_EN.htm#_report_designer_preview
SP1 can be downloaded here:
http://www.microsoft.com/downloads/details.aspx?FamilyId=580FEBF7-2972-40E7-BCCF-6CD90AC2F464&displaylang=en
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Stefan Wrobel" <StefanWrobel@.discussions.microsoft.com> wrote in message
news:FD067DE7-1DD1-463F-90E1-F835206D966C@.microsoft.com...
>I do a lot of work with a report that calls a stored procedure that takes
> about 2 minutes to complete. It annoys me that when I change one little
> formatting property in the layout, I have to wait for the stored procedure
> to
> run again before I can see the results of my modification. I wish that I
> could just cache the dataset created by this stored procedure when I'm
> testing in Visual Studio and avoid rerunning it each time I change the
> formatting. Can anyone tell me if this is possible? Thanks.
Saturday, February 25, 2012
Possible Concurrency Issues.
I was wondering if it is possible to call a stored procedure from sql server 2005 (call it sp_1) that calls an assembly which takes a message, wraps it in soap and calls a webservice and waits for a reply from that webservice (the stored procedure is clr not t-sql). This WebService needs to then call sp_1 to perform some other tasks. Is this possible or does sp_1 need to have finished what it was doing before it can be called again.
I have been trying to do this and have received a number of errors one of which looks like;
'The context connection is already in use.'
Sorry if I haven't worded it very well, I will try to clear up any questions if you need me to.
Thanks
N
Dont worry about replying to this, I have done some more research and the I was trying to open multiple context connections when only 1 is allowed at a time, which was creating the error.