Tuesday, March 27, 2012
Can not insert input field with length gt 128
insert records into SQL. When the field of input string contained more than
128 characters, it gave me this message:
The identifier that starts with 'Today is a nice day..........Good bye'
is too long. Maximum length is 128.
But here I am not sending in an identifier name, I am sending in the actual
input which is more than 128 characters long. The input field in the data
base is defined as varchar(1000).
Any ideas?What is the size on the parameter declaration in the stored procedure? I'll
bet you a shiny new nickel it's VARCHAR(128) or CHAR(128).
"pelican" <pelican@.discussions.microsoft.com> wrote in message
news:D4B955D4-C318-4E38-BB9F-77B439561881@.microsoft.com...
>I got this problem that really puzzled me. I used a stored procedure to
> insert records into SQL. When the field of input string contained more
> than
> 128 characters, it gave me this message:
> The identifier that starts with 'Today is a nice day..........Good bye'
> is too long. Maximum length is 128.
> But here I am not sending in an identifier name, I am sending in the
> actual
> input which is more than 128 characters long. The input field in the data
> base is defined as varchar(1000).
> Any ideas?|||> What is the size on the parameter declaration in the stored procedure?
> I'll bet you a shiny new nickel it's VARCHAR(128) or CHAR(128).
Actually, it sounds like the call he is making to the database doesn't
properly encapsulate this string. It seems SQL Server has mistaken the
string for an identifier (otherwise the error would be "string or binary
data would be truncated"). This usually happens when someone uses " instead
of ' for delimiting a string, but there are other possibilities as well.
"pelican", how about showing us the actual code you are using, instead of
vaguely describing it -- then we don't have to guess. I suppose DDL for the
table you are trying to INSERT into wouldn't hurt either (see
http://www.aspfaq.com/5006).|||Good point, probably an embedded ' in the input somewhere that wasn't
properly escaped by the app. Interesting that it would pick 128 as the
cut-off size, however. I would definitely need to see the code for the SP
and the input string.
"AB - MVP" <ten.xoc@.dnartreb.noraa> wrote in message
news:u6KSE6AUFHA.2712@.TK2MSFTNGP09.phx.gbl...
> Actually, it sounds like the call he is making to the database doesn't
> properly encapsulate this string. It seems SQL Server has mistaken the
> string for an identifier (otherwise the error would be "string or binary
> data would be truncated"). This usually happens when someone uses "
> instead of ' for delimiting a string, but there are other possibilities as
> well.
> "pelican", how about showing us the actual code you are using, instead of
> vaguely describing it -- then we don't have to guess. I suppose DDL for
> the table you are trying to INSERT into wouldn't hurt either (see
> http://www.aspfaq.com/5006).
>|||> Good point, probably an embedded ' in the input somewhere that wasn't
> properly escaped by the app. Interesting that it would pick 128 as the
> cut-off size, however.
That is the maximum size for an identifier. I don't think it is an errant
', it just received this string that it thinks is supposed to be a column,
and is saying, WHOA, this column name is bigger than 128, hold on. It could
be 129 or 8000 characters... the same error will get kicked out.|||Thank you all so much! "AB - MVP" is right, once I changed the double quote
(") to single ('), it worked fine! In the stored procedure, the size on the
parameter is varchar(1000). I did not realize that the "" sign will make SQ
L
believe I was passing an identifier instead of the actually content.
You are my life saver...
"AB - MVP" wrote:
> Actually, it sounds like the call he is making to the database doesn't
> properly encapsulate this string. It seems SQL Server has mistaken the
> string for an identifier (otherwise the error would be "string or binary
> data would be truncated"). This usually happens when someone uses " inste
ad
> of ' for delimiting a string, but there are other possibilities as well.
> "pelican", how about showing us the actual code you are using, instead of
> vaguely describing it -- then we don't have to guess. I suppose DDL for th
e
> table you are trying to INSERT into wouldn't hurt either (see
> http://www.aspfaq.com/5006).
>
>|||I read about the identifier length in the help section. It said the same
thing as AB-MVP pointed out, that 128 is the maximum length per row for an
identifier. I just never dreamed that a " will do it.
Thanks a lot!|||Yeah it's called a "quoted identifier" and can be circumvented by using
"parameterized queries".
"pelican" <pelican@.discussions.microsoft.com> wrote in message
news:6F3F8CAB-1EBD-45A6-BF74-4DC272EA1804@.microsoft.com...
> Thank you all so much! "AB - MVP" is right, once I changed the double
> quote
> (") to single ('), it worked fine! In the stored procedure, the size on
> the
> parameter is varchar(1000). I did not realize that the "" sign will make
> SQL
> believe I was passing an identifier instead of the actually content.
> You are my life saver...
> "AB - MVP" wrote:
>|||Yep that's what they get for slapping a SQL statement together with +'s
instead of using parameterized queries.
"AB - MVP" <ten.xoc@.dnartreb.noraa> wrote in message
news:uGWbvCBUFHA.1896@.TK2MSFTNGP14.phx.gbl...
> That is the maximum size for an identifier. I don't think it is an errant
> ', it just received this string that it thinks is supposed to be a column,
> and is saying, WHOA, this column name is bigger than 128, hold on. It
> could be 129 or 8000 characters... the same error will get kicked out.
>
Monday, March 19, 2012
Can multiple stored procs be printed all at once.
choose all the SPs that you want to print,
right click one of the SPs and choose All Tasks/Generate SQL script
save the script to a file
open the file
"Andy" <Andy@.discussions.microsoft.com> wrote in message
news:B3A790D9-11B8-4032-93D4-F540FA7ECE89@.microsoft.com...
> Can multiple stored procs be printed all at once.
Sunday, March 11, 2012
Can it be done?
DECLARE @.IsDuplicate NVARCHAR(5);SET @.IsDuplicate = (SELECT IsDuplicate FROM User_Notes WHERE FK_UN_UserID = @.FK_UserID AND FK_UN_NoteID = @.NoteID) -- Is it an admin note
the
@.FK_UserID = 3
@.NoteID = 5
the table
FK_UN_UserID : FK_UN_NoteID : IsDuplicate
1 3 False
2 4 True
3 5 True
I need to get the value of IsDuplicate where FK_UN_UserID = 3
and FK_UN_NoteID = 5, the result would give 'true', but its not??
I'm baffledlet me get this straight. you're storing True or False in an NVarChar? Why not a bit?
Anyways... Try this.
IF (SELECT Count(*) FROM User_Notes WHERE FK_UN_UserID = 5 AND FK_UN_NoteID = 3) > 1
BEGIN
Print 'You got dupes buddy'
END
--
IF (SELECT Count(*) FROM User_Notes WHERE FK_UN_UserID = 3 AND FK_UN_NoteID = 5) > 0
BEGIN
Print 'You got your params flipped buddy'
END|||Syntax:
SELECT @.IsDuplicate = IsDuplicate FROM User_Notes WHERE FK_UN_UserID = @.FK_UserID AND FK_UN_NoteID = @.NoteID|||whats wrong with using nvarchar, how would I use a bit, forgive my ignorance!!|||A bit field is meant for true-false values. It can hold only a 1 or 0. It's just a more efficient way of storing a boolean value.|||But it is also more difficult to make use of data stored that way, plus if you have only 1 bit column it will still take a whole byte to store the data.
We typically use tinyint for this sort of data. This also prepares us for when the client suddenly decides that they need to store "Maybe" in addition to "Yes" and "No".
Just my 2 cents.
Terri|||I though tinyInt would have only allowed integers as opposed to "Yes", "No" "Maybe". Am I wrong?|||You are definitely correct. I use a separate lookup table to convert the integer value to its friendly name.
Terri|||Does that approach have significant advantages? In other words does it really make a considerable differance to speed etc using lookup tables like you have done or is that just a design preference?|||To be honest, we've used a mix of lookup tables and hardcoding in the front end. It has to be faster not to use lookup tables, but it's cleaner and takes up less space to just use a tinyint.
Also, you have prompted me to review the reasons we decided to use tinyints instead of bits. In case anyone is interested:
We found that different front ends would treat the bit data differently. VB6 in particular, I think, had some issues trying to convert a Boolean variable into a bit type. ADO did not translate bit into boolean -- at least not correctly or intuitively.
Issues I have seen with SQL Server:
-- MAX() will not accept a bit value, need to CAST the bit field as int or tinyint
And, as I mentioned, if the database design is changed from "yes/no" to "yes/no/maybe" the datatype would need to change and there would be related code changes.
Terri|||Also, lookup tables provide a consistent place to find your answers...you don't have to go tracking through your code to try and remember where you documented what your #'s represented. It pays of when you come back to your code several months later.
I agree with terri 100% on this one.|||Well...
There is an advantage to using the BIT column. For example, if you know that there must be a value, and you know that it is a true/false response, then why not use a bit? You can always allow a NULL value for 'maybe' cases, if necessary.
Personally, I only use bit when there is real true/false data to be stored, but I certainly wouldn't use a bit for such circumstances. For example, an IsActive field on a company record; why would you want a maybe as your response? If we send out a mailing to all active customers, maybe isn't going to help us at all. Either they are active, or they are not active. If we're not sure, we need to decide whtether we treat them as active or inactive (i.e., assign a default value).|||What if you decide to impliment more business logic...what if you decide that you want subscribers to go into a holding tank where they must be approved...before they can be on the mailing list. Then you would need a value to indicate that the are pending approval.
or maybe you have a delay in the system. Where you mark someone to be taken off the list..but they have to wait till the end of the month to be taken off the list. (like when you call people who are sending you junk mail and they tell you it will take 2 months till you stop getting mail...because they love sending you crap)
The point is...you never know when something will come up...why cut your legs off and use a bit, when an int functions just as good...and leaves you with more options in the future?|||Don't get me wrong here. There are many times when I will use a lookup table. However, if your analysis is solid, you should be able to discern these from actual true/false circumstances that arise in any database structures. And I think that such circumstances are best served using a bit value.
Thursday, March 8, 2012
Can Iif be used to change query result?
I'm converting a set of queries from Access to work as stored procedures on SQL server, and one of them that uses IIF gives me a syntax error. Here's the WHERE clause of the SELECT:
WHERE IIF(@.myExtNum > 0,D.ExtentionNumber=@.myExtNum,'') AND ...
I get the error message "syntax error near '>'."
It would seem this query wants to do two things: 1) if @.myExtNum is >0, return only the rows for which D.ExtentionNumber equals a user specified value, or 2) if @.myExtNum is 0 ignore this part of the condition.
I can rewrite this using multiple ANDs and ORs, but I wodered if there was a way I could get IIF working.
Something in my gut tells me this is not going to work, that IIF is being used to modify the query; that is, change which rows are returned; it is not being used to change how a given data value is displayed, which I think was the purpose for which IIF was originally intended.
Does anyone have an insight on this?
Hello,
Sorry, but IIF isn't a valid T-SQL function. You could do this instead (if D.ExtentionNumber is not nullable):
where D.ExtentionNumber =
case
when @.myExtNum > 0 then @.myExtNum
else D.ExtentionNumber
end
If it is nullable, do this instead (the -1 is an arbitrary value that is not available to the field):
where coalesce(D.ExtentionNumber, -1) =
case
when @.myExtNum > 0 then @.myExtNum
else coalesce(D.ExtentionNumber, -1)
end
Hope this helps.
Jarret
Can I validate this xml somehow?
varchar *Should* be a valid xml and should represent a pre-defined schema.
How can I validate that the xml is a valid schema?
I need to ensure that the root node is <s>, that it can have many <p> nodes
but no other nodes, and each <p> node must have a 'n' and a 'v' attribute.
My test stored proc is as follows:
CREATE PROCEDURE dbo.pXMLTest
@.strXML varchar(1024)
AS
DECLARE @.idoc int
EXECUTE sp_xml_preparedocument @.idoc OUTPUT, @.strXML
--Must validate that the schema is correct
SELECT
n,v
FROM
OpenXML(@.idoc,'/s/p')
WITH
(n varchar(1024),
v varchar(1024))
EXECUTE sp_xml_removedocument @.iDoc
GO
/* Test code
--valid
pXMLTest '<s>
<p n="param1" v="value1"/>
<p n="param2" v="value2"/>
</s>'
--invalid, stored proc should return an error
pXMLTest '<s>
<x n="param1" v="value1"/>
<p n="param2" v="value2"/>
</s>'
*/
You do not have a schema validator in SQL Server 2000. You would have to
validate on the client/midtier using either MSXML (native code) or
System.XML (.Net Framework) if you have an XML schema.
Inside the database, you can do some query based validation (see below for
an example). However, that is quite expensive compare to using a schema and
a validator.
So, to validate that the top-level node is s that can only have p elements
as child nodes and p nodes must have an n and v attribute, we can make use
of the node table of the XML structure. Since we need to self-join/access
the structure several times, we use a temp table to store the data. You can
use the following statements to help build your stored proc:
-- The following are some test cases
--N'<s><p a="a1" n="n1" v="v1"/><p n="n2" v="v2"/></s>'
--N'<r><p n="n1" v="v1"/><p n="n2" v="v2"/></r>'
--N'<s><p a="a1" n="n1" v="v1"/><p n="n2" v="v2"/></s>'
--N'<s><q a="a1" n="n1" v="v1"/><p n="n2" v="v2"/></s>'
--N'<s><p n="n1" v="v1"/><p n="n2" v="v2"/></s>'
--N'<s><p v="v1"/><p n="n2"/></s>'
--N'<s>text<p n="n1" v="v1"/><p n="n2" v="v2"/></s>'
--N'<s><?pi?><p n="n1" v="v1"/><p n="n2" v="v2"/></s>'
--N'<s><x n="param1" v="value1"/><p n="param2" v="value2"/></s>'
--N'<s/>'
--N'<s><p/><p/></s>'
--N'<s><p><n>n1</n><v>v1</v></p><p n="n2" v="v2"/></s>'
--N'<s><p n="n1" v="v1">a</p><p n="n2" v="v2"/></s>'
SELECT * INTO #T FROM OpenXML(@.idoc, '/s') -- Make sure that we have an s
element root
-- The following returns pass if the conditions hold.
-- Note that the root element always has id 0 and has always parentid NULL
which simplifies some of the subselects
SELECT CASE WHEN count(*)= 0 THEN 'fail' ELSE 'pass' END
from #T as T
WHERE -- Check for p elements
T.localname = N'p' and T.namespaceuri IS NULL AND T.nodetype=1
AND -- that have an s parent that is the root element (note there cannot be
another root)
T.parentid in
(SELECT id from #T as Tp WHERE
Tp.localname = N's' and Tp.namespaceuri IS NULL and Tp.parentid IS NULL)
AND -- no other nodes under the root element exists other than p elements
NOT EXISTS(
SELECT id from #T as Ts WHERE
Ts.parentid = 0 and
(Ts.localname<>N'p' or NOT(Ts.namespaceuri is null or Ts.nodetype<>1) ))
AND -- all p elements have attributes
EXISTS(
SELECT id from #T as Ta
WHERE Ta.parentid = T.id and Ta.nodetype = 2
)
AND -- all p elements have both v and n attributes
2= ALL (
SELECT count(id)
from #T Ta
WHERE Ta.parentid IN (SELECT Ts.id FROM #T as Ts WHERE Ts.parentid = 0)
AND Ta.nodetype = 2 AND
(namespaceuri IS NULL AND localname = N'v'
OR namespaceuri IS NULL AND localname = N'n')
group by Ta.parentid
)
AND -- none of the p elements have non-v or n attributes or non attribute
children
0 = ALL(
SELECT count(id)
from #T Ta
WHERE Ta.parentid IN (SELECT Ts.id FROM #T as Ts WHERE Ts.parentid = 0)
AND (NOT(
Ta.namespaceuri IS NULL AND Ta.localname = N'v'
OR Ta.namespaceuri IS NULL AND Ta.localname = N'n'
) OR Ta.nodetype <> 2))
drop table #T
I have tested the statement with the examples above and am almost sure that
you probably could write it more efficiently.
HTH
Michael
"Jeremy Chapman" <NoSpam@.Please.com> wrote in message
news:uGyjKlx3EHA.3504@.TK2MSFTNGP12.phx.gbl...
>I have a stored procedure which takes a varchar. the contents of the
> varchar *Should* be a valid xml and should represent a pre-defined schema.
> How can I validate that the xml is a valid schema?
> I need to ensure that the root node is <s>, that it can have many <p>
> nodes
> but no other nodes, and each <p> node must have a 'n' and a 'v' attribute.
> My test stored proc is as follows:
> CREATE PROCEDURE dbo.pXMLTest
> @.strXML varchar(1024)
> AS
> DECLARE @.idoc int
> EXECUTE sp_xml_preparedocument @.idoc OUTPUT, @.strXML
> --Must validate that the schema is correct
> SELECT
> n,v
> FROM
> OpenXML(@.idoc,'/s/p')
> WITH
> (n varchar(1024),
> v varchar(1024))
> EXECUTE sp_xml_removedocument @.iDoc
> GO
> /* Test code
> --valid
> pXMLTest '<s>
> <p n="param1" v="value1"/>
> <p n="param2" v="value2"/>
> </s>'
> --invalid, stored proc should return an error
> pXMLTest '<s>
> <x n="param1" v="value1"/>
> <p n="param2" v="value2"/>
> </s>'
> */
>
|||Brilliant! Excellent. Thanks.
"Michael Rys [MSFT]" <mrys@.online.microsoft.com> wrote in message
news:O#RcS813EHA.1596@.tk2msftngp13.phx.gbl...
> You do not have a schema validator in SQL Server 2000. You would have to
> validate on the client/midtier using either MSXML (native code) or
> System.XML (.Net Framework) if you have an XML schema.
> Inside the database, you can do some query based validation (see below for
> an example). However, that is quite expensive compare to using a schema
and
> a validator.
> So, to validate that the top-level node is s that can only have p elements
> as child nodes and p nodes must have an n and v attribute, we can make use
> of the node table of the XML structure. Since we need to self-join/access
> the structure several times, we use a temp table to store the data. You
can
> use the following statements to help build your stored proc:
> -- The following are some test cases
> --N'<s><p a="a1" n="n1" v="v1"/><p n="n2" v="v2"/></s>'
> --N'<r><p n="n1" v="v1"/><p n="n2" v="v2"/></r>'
> --N'<s><p a="a1" n="n1" v="v1"/><p n="n2" v="v2"/></s>'
> --N'<s><q a="a1" n="n1" v="v1"/><p n="n2" v="v2"/></s>'
> --N'<s><p n="n1" v="v1"/><p n="n2" v="v2"/></s>'
> --N'<s><p v="v1"/><p n="n2"/></s>'
> --N'<s>text<p n="n1" v="v1"/><p n="n2" v="v2"/></s>'
> --N'<s><?pi?><p n="n1" v="v1"/><p n="n2" v="v2"/></s>'
> --N'<s><x n="param1" v="value1"/><p n="param2" v="value2"/></s>'
> --N'<s/>'
> --N'<s><p/><p/></s>'
> --N'<s><p><n>n1</n><v>v1</v></p><p n="n2" v="v2"/></s>'
> --N'<s><p n="n1" v="v1">a</p><p n="n2" v="v2"/></s>'
> SELECT * INTO #T FROM OpenXML(@.idoc, '/s') -- Make sure that we have an s
> element root
> -- The following returns pass if the conditions hold.
> -- Note that the root element always has id 0 and has always parentid NULL
> which simplifies some of the subselects
> SELECT CASE WHEN count(*)= 0 THEN 'fail' ELSE 'pass' END
> from #T as T
> WHERE -- Check for p elements
> T.localname = N'p' and T.namespaceuri IS NULL AND T.nodetype=1
> AND -- that have an s parent that is the root element (note there cannot
be
> another root)
> T.parentid in
> (SELECT id from #T as Tp WHERE
> Tp.localname = N's' and Tp.namespaceuri IS NULL and Tp.parentid IS NULL)
> AND -- no other nodes under the root element exists other than p elements
> NOT EXISTS(
> SELECT id from #T as Ts WHERE
> Ts.parentid = 0 and
> (Ts.localname<>N'p' or NOT(Ts.namespaceuri is null or Ts.nodetype<>1) ))
> AND -- all p elements have attributes
> EXISTS(
> SELECT id from #T as Ta
> WHERE Ta.parentid = T.id and Ta.nodetype = 2
> )
> AND -- all p elements have both v and n attributes
> 2= ALL (
> SELECT count(id)
> from #T Ta
> WHERE Ta.parentid IN (SELECT Ts.id FROM #T as Ts WHERE Ts.parentid = 0)
> AND Ta.nodetype = 2 AND
> (namespaceuri IS NULL AND localname = N'v'
> OR namespaceuri IS NULL AND localname = N'n')
> group by Ta.parentid
> )
> AND -- none of the p elements have non-v or n attributes or non attribute
> children
> 0 = ALL(
> SELECT count(id)
> from #T Ta
> WHERE Ta.parentid IN (SELECT Ts.id FROM #T as Ts WHERE Ts.parentid = 0)
> AND (NOT(
> Ta.namespaceuri IS NULL AND Ta.localname = N'v'
> OR Ta.namespaceuri IS NULL AND Ta.localname = N'n'
> ) OR Ta.nodetype <> 2))
> drop table #T
> I have tested the statement with the examples above and am almost sure
that[vbcol=seagreen]
> you probably could write it more efficiently.
> HTH
> Michael
> "Jeremy Chapman" <NoSpam@.Please.com> wrote in message
> news:uGyjKlx3EHA.3504@.TK2MSFTNGP12.phx.gbl...
schema.[vbcol=seagreen]
attribute.
>
Can I use varible here in Stored Procedure?
There are two webpages in my website. one displays 10 articles last updated
and another one displays 6 articles last updated. So I want to use only one
procedure to do this, and wrote the following code:
CREATE PROCEDURE [dbo].[articleLastUpdated]
(
@.nNumber smallint
)
AS
SELECT TOP @.nNumber Title, Link From MYARTICLES Order By DATEADDED Desc;
GO
Unfortunately, SQL always prompt me a Syntax error. Is there any way to do
it? Or I must to write two procedures? thanks!Hi,
If you are using SQL 2005 you can do this...
declare @.rows int
set @.rows = 10
select top (@.rows) * from sys.objects
Remember you need the brackets round @.rows!
If not, you can use set rowcount...
SET ROWCOUNT @.nNumber
SELECT Title, Link ... ORDER ..
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"mizi" <haha@.haha.com> wrote in message
news:Xns9718D21D69A72hahahahacom@.207.46.248.16...
> Hi.
> There are two webpages in my website. one displays 10 articles last
> updated
> and another one displays 6 articles last updated. So I want to use only
> one
> procedure to do this, and wrote the following code:
> CREATE PROCEDURE [dbo].[articleLastUpdated]
> (
> @.nNumber smallint
> )
> AS
> SELECT TOP @.nNumber Title, Link From MYARTICLES Order By DATEADDED Desc;
> GO
> Unfortunately, SQL always prompt me a Syntax error. Is there any way to do
> it? Or I must to write two procedures? thanks!|||"Tony Rogerson" <tonyrogerson@.sqlserverfaq.com> wrote in
news:O8eKNjT8FHA.3760@.TK2MSFTNGP14.phx.gbl:
> Hi,
> If you are using SQL 2005 you can do this...
> declare @.rows int
> set @.rows = 10
> select top (@.rows) * from sys.objects
>
> Remember you need the brackets round @.rows!
> If not, you can use set rowcount...
> SET ROWCOUNT @.nNumber
> SELECT Title, Link ... ORDER ..
>
Is there any difference between use 'select top' and 'set rowcount'? for
example, the efficiency?|||you could do this
CREATE PROCEDURE [dbo].[articleLastUpdated]
(
@.nNumber smallint
)
AS
exec('SELECT TOP ' + @.nNumber + ' Title, Link From MYARTICLES Order By
DATEADDED Desc;')
GO
regards
Michel Posseth [MCP]
"mizi" <haha@.haha.com> wrote in message
news:Xns9718D21D69A72hahahahacom@.207.46.248.16...
> Hi.
> There are two webpages in my website. one displays 10 articles last
> updated
> and another one displays 6 articles last updated. So I want to use only
> one
> procedure to do this, and wrote the following code:
> CREATE PROCEDURE [dbo].[articleLastUpdated]
> (
> @.nNumber smallint
> )
> AS
> SELECT TOP @.nNumber Title, Link From MYARTICLES Order By DATEADDED Desc;
> GO
> Unfortunately, SQL always prompt me a Syntax error. Is there any way to do
> it? Or I must to write two procedures? thanks!|||Yes there is, also depends what you are doing and whats indexed before you
notice.
Doing a test on a table with 730,000 rows in it i ran the following SQL and
the plans where very similar except the sort step on the TOP had 10 rows,
the ROWCOUNT had the whole table, the IO statistics are as follows:-
With TOP...
Table 'mb_message'. Scan count 1, logical reads 11889, physical reads 7,
read-ahead reads 11694.
(10 row(s) affected)
Table 'mb_message'. Scan count 1, logical reads 11889, physical reads 4,
read-ahead reads 1978.
(10 row(s) affected)
Basically they are the same, the read-ahead are different because a lot of
the data would have been in the cache from the previous read.
Personally, if you are using 2000 i'd use SET ROWCOUNT simply because you
don't have to use dynamic SQL which would mean you have to permission the
base tables to the user instead of just execute on the stored procedure,
other than that - use 2005 :)
Tony.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"mizi" <haha@.haha.com> wrote in message
news:Xns9718D507C333hahahahacom@.207.46.248.16...
> "Tony Rogerson" <tonyrogerson@.sqlserverfaq.com> wrote in
> news:O8eKNjT8FHA.3760@.TK2MSFTNGP14.phx.gbl:
>
> Is there any difference between use 'select top' and 'set rowcount'? for
> example, the efficiency?|||mizi <haha@.haha.com> wrote in
news:Xns9718D21D69A72hahahahacom@.207.46.248.16:
> There are two webpages in my website. one displays 10 articles last
> updated and another one displays 6 articles last updated. So I want to
> use only one procedure to do this, and wrote the following code:
> CREATE PROCEDURE [dbo].[articleLastUpdated]
> (
> @.nNumber smallint
> )
> AS
> SELECT TOP @.nNumber Title, Link From MYARTICLES Order By DATEADDED
> Desc; GO
> Unfortunately, SQL always prompt me a Syntax error. Is there any way
> to do it? Or I must to write two procedures? thanks!
select top (@.variable) was introduced in sql server 2005. Note the
parentheses. For SQL server 2000 and before you have to use:
set rowcount @.variable
select title, link...
set rowcount 0
Ole Kristian Bangs
MCT, MCDBA, MCDST, MCSE:Security, MCSE:Messaging
Can I use the 'IF' clause in a 'WHERE' clause ?
I am developing a website using MS Visual Studio 2005 and SQL 2005 Express.
I'm using SQL queries (not stored procedures yet).
Problem:
I have a query that I can't make work. I found the COALESCE function and it
solves part of the problem but not all.
I have a variable '@.filter_by_date' which is bound to a dropdownlist on the
webpage. The dropdownlist's values are NULL, -7, -14, -30 which represent th
e
number of days to subtract from today's date.
If a user selects the NULL option the query should return all rows which is
how my query is:
SELECT * FROM t_jobs WHERE (created_date >= COALESCE(@.filter_by_date,
created_date))
The problem arises when the user selects any of the other options. If the
user selects -7, for example, then this value should be subtracted from the
current date and used in the query to only show jobs created after that date
.
The query looks like this:
SELECT * FROM t_jobs WHERE (created_date >= GETDATE() -@.filter_by_date)
Is it possible to merge the two queries? I thought of trying to use an 'IF'
in the 'WHERE' clause but I can't get it to work.
Thank you for your time. Hope you can help.You'll probably get better performance with two separate queries, each in
its own stored proc. However, you can try:
SELECT
*
FROM
t_jobs
WHERE
@.filter_by_date IS NULL
OR (@.filter_by_date IS NOT NULL
AND created_date >= GETDATE() -@.filter_by_date))
(assumes @.filter_by_date is a positive number.)
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
"Matthew Hill" <MatthewHill@.discussions.microsoft.com> wrote in message
news:6AA25C85-C8B9-48FB-8AE6-8850E0A03161@.microsoft.com...
> Background:
> I am developing a website using MS Visual Studio 2005 and SQL 2005
> Express.
> I'm using SQL queries (not stored procedures yet).
> Problem:
> I have a query that I can't make work. I found the COALESCE function and
> it
> solves part of the problem but not all.
> I have a variable '@.filter_by_date' which is bound to a dropdownlist on
> the
> webpage. The dropdownlist's values are NULL, -7, -14, -30 which represent
> the
> number of days to subtract from today's date.
> If a user selects the NULL option the query should return all rows which
> is
> how my query is:
> SELECT * FROM t_jobs WHERE (created_date >= COALESCE(@.filter_by_date,
> created_date))
> The problem arises when the user selects any of the other options. If the
> user selects -7, for example, then this value should be subtracted from
> the
> current date and used in the query to only show jobs created after that
> date.
> The query looks like this:
> SELECT * FROM t_jobs WHERE (created_date >= GETDATE() -@.filter_by_date)
> Is it possible to merge the two queries? I thought of trying to use an
> 'IF'
> in the 'WHERE' clause but I can't get it to work.
> Thank you for your time. Hope you can help.
>|||Thanks for the help. I implemented your querry into mine but when I go out o
f
and back into the Query Builder the query has changed. My other comparisons
in the WHERE clause have been duplicated for each side of the OR operator. I
s
this normal?
"Tom Moreau" wrote:
> You'll probably get better performance with two separate queries, each in
> its own stored proc. However, you can try:
> SELECT
> *
> FROM
> t_jobs
> WHERE
> @.filter_by_date IS NULL
> OR (@.filter_by_date IS NOT NULL
> AND created_date >= GETDATE() -@.filter_by_date))
> (assumes @.filter_by_date is a positive number.)
>
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> "Matthew Hill" <MatthewHill@.discussions.microsoft.com> wrote in message
> news:6AA25C85-C8B9-48FB-8AE6-8850E0A03161@.microsoft.com...
>
>|||Don't use the query builder. Use Query Analyzer (QA).
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Matthew Hill" <MatthewHill@.discussions.microsoft.com> wrote in message
news:A944E1F3-C855-441C-8F90-F4ED600E33F1@.microsoft.com...
> Thanks for the help. I implemented your querry into mine but when I go out
> of
> and back into the Query Builder the query has changed. My other
> comparisons
> in the WHERE clause have been duplicated for each side of the OR operator.
> Is
> this normal?
> "Tom Moreau" wrote:
>|||Thank you for your prompt replies, much appreciated.
Ok, stupid question but here goes. Is QA in SQL Server? I'm not using SQL
Server yet, waiting until my Visual Studio 2005 Pro turns up (any day now)
before I dable into yet another app.
Mat
"Tom Moreau" wrote:
> Don't use the query builder. Use Query Analyzer (QA).
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada tom@.cips.ca
> www.pinpub.com
> "Matthew Hill" <MatthewHill@.discussions.microsoft.com> wrote in message
> news:A944E1F3-C855-441C-8F90-F4ED600E33F1@.microsoft.com...
>
>|||If you have SQL Server 2000, that's part of the tools that ship with it. If
you have SQL Server 2005, then you use SQL Server Management Studio (SSMS),
that ships with SQL Server 2005.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Matthew Hill" <MatthewHill@.discussions.microsoft.com> wrote in message
news:476B52A3-1188-46DE-AF3F-B905475B1A1D@.microsoft.com...
Thank you for your prompt replies, much appreciated.
Ok, stupid question but here goes. Is QA in SQL Server? I'm not using SQL
Server yet, waiting until my Visual Studio 2005 Pro turns up (any day now)
before I dable into yet another app.
Mat
"Tom Moreau" wrote:
> Don't use the query builder. Use Query Analyzer (QA).
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada tom@.cips.ca
> www.pinpub.com
> "Matthew Hill" <MatthewHill@.discussions.microsoft.com> wrote in message
> news:A944E1F3-C855-441C-8F90-F4ED600E33F1@.microsoft.com...
>
>
Can I use stored procedures with PHP via ODBC bridge?
I am a stored procedures newbie, so I wanted to ask if it is possible
to use them with PHP via an ODBC-ODBC bridge connected to a MS SQL
server. I am simply use the commands from the php odbc library to
connect and execute the SQL commands, I am trying to avoid building
dynamic queries, so stored proceddures seem to be the answer. I know
that there are only certain environments stored procedures can be used
within. Thank you for all of your help.Storedprocs can be started through queries which should not bring any
problems in using them with PHP, but test it.
I don't know how the query_resource (return value) is handled in a
Stored proc but I believe any return values wll be returned in fieldlike
structures.
Anyway thats how it works in Pascal...
Working in PHP&MySQL platforms haven't given me the opportunity to test
that functionality in PHP.
Regards,
Toke Herkild
gene.ellis@.gmail.com wrote:
> Hey Everyone,
> I am a stored procedures newbie, so I wanted to ask if it is possible
> to use them with PHP via an ODBC-ODBC bridge connected to a MS SQL
> server. I am simply use the commands from the php odbc library to
> connect and execute the SQL commands, I am trying to avoid building
> dynamic queries, so stored proceddures seem to be the answer. I know
> that there are only certain environments stored procedures can be used
> within. Thank you for all of your help.|||Yes, it it is possible, and works OK.
Check out the latest PHP manual ==> Function Reference ==> Microsoft
SQL Server Functions ==> mssql_execute().
HTH,
Rob
Wednesday, March 7, 2012
can I use sql profiler to debug stored procedure
get from client side. Thanks
Asked and answered in .programming group... Please do not multi-post.
"iter" <anonymous@.discussions.microsoft.com> wrote in message
news:17B8A330-6E4E-487A-9229-6493EF9DBBA5@.microsoft.com...
> can I use sql profiler to debug stored procedure, for example, when
application runing, can I get infomation in profiler, such as value of
variable in stored procedure, especially input parameter. Because I need to
know what is value of input parameter I get from client side. Thanks
>
Can I use my own Stored Procedure template with SQL2005?
When I go to create a new stored procedure, function, etc. I get a default template... is there anyway to replace this template with one of my own? One that will already have the important information pre-populated (the stuff I always end up having to type in, like company name, etc.).
Hi,
in SQL Server Management Studio, choose View -> Template Explorer. (Or Ctrl + Alt + T). There you can manage templates. Edit them whatsoever.
Saturday, February 25, 2012
Can I use Hyperlinks in a SQL Server CE database?
Specifically, I would like to have the link point to an .jpg file stored in a folder on the computer.
Thanks!The "hyperlink" field type is not supported, by you can store text in a SQL CE database, both the Hyperlink description and the file path (in 2 nvarchar fields)
Can I use dynamic SQL in a stored procedure to call another stored
I am having one stored procedure named SP1 which is having one input and one
output parameter as follows
CREATE PROCEDURE dbo.SP1
@.xmldoc TEXT
,@.FLAG_EXEC VARCHAR(5)
AS
BEGIN
...
END
I have write another stored procedure named SP2 which is creating a dynamic
SQL statement like
CREATE PROCEDURE dbo.SP2
AS
BEGIN
DECLARE @.CURR_PROC_NAME VARCHAR(125)
DECLARE @.STR_XML_AS_VARCHAR VARCHAR(125)
DECLARE @.STR_RET_QRY_MN VARCHAR(125)
DECLARE @.STR_EXECUTE_QRY VARCHAR(4000)
SET @.STR_EXECUTE_QRY = 'exec ' + @.CURR_PROC_NAME + ''''+
@.STR_XML_AS_VARCHAR + ''' , @.STR_RET_QRY_MN OUTPUT ,@.FLAG_EXEC = ''FALSE'' '
print @.STR_EXECUTE_QRY
EXEC (@.STR_EXECUTE_QRY)
END
but it always says to declare @.STR_RETURN_STRING variable. Can I do like
above? If yes then how? If no then why?
With thanx in advance,Hi Rajendra,
this does not work because each EXEC is running in it's own process.
That means in fact that proc2 does not know anything about the variables
you have declared in proc1.
You should handle it as follows:
Proc2 (Sub-Proc) writes the ReturnValue into a table
Proc2 (Calling Proc) reads after the run of Proc2 the value from the table
Another way is to work with "sp_executesql". See BOL for details...
HTH ;-)
Gru, Uwe Ricken
MCP for SQL Server 2000 Database Implementation
GNS GmbH, Frankfurt am Main
http://www.gns-online.de
http://www.memberadmin.de
http://www.conferenceadmin.de
________________________________________
____________
dbdev: http://www.dbdev.org
APP: http://www.AccessProfiPool.de
FAQ: http://www.donkarl.com/AccessFAQ.htm|||Rajendra (Rajendra@.discussions.microsoft.com) writes:
> I have write another stored procedure named SP2 which is creating a
> dynamic SQL statement like
> CREATE PROCEDURE dbo.SP2
> AS
> BEGIN
> DECLARE @.CURR_PROC_NAME VARCHAR(125)
> DECLARE @.STR_XML_AS_VARCHAR VARCHAR(125)
> DECLARE @.STR_RET_QRY_MN VARCHAR(125)
> DECLARE @.STR_EXECUTE_QRY VARCHAR(4000)
> SET @.STR_EXECUTE_QRY = 'exec ' + @.CURR_PROC_NAME + ''''+
> @.STR_XML_AS_VARCHAR + ''' , @.STR_RET_QRY_MN OUTPUT ,@.FLAG_EXEC = ''FALSE''
'
> print @.STR_EXECUTE_QRY
> EXEC (@.STR_EXECUTE_QRY)
> END
> but it always says to declare @.STR_RETURN_STRING variable. Can I do like
> above? If yes then how? If no then why?
You are making it too complicated. Just say:
EXEC @.CURR_PROC_NAME @.STR_XML_AS_VARCHAR, STR_RET_QRY_MN OUTPUT,
@.FLAG_EXEC = 'FALSE'
This will execute the procedure of which the name is in @.CURR_PROC_NAME.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx
Can I use dimension in SQL SERVER 2005?
I hope to pass a dimension such as int A[5] to a stored procedure
A[0]=10
A[1]=20
...
Can I do that in sql server 2005? if so , please give me a sample, thanks!
I dont think you can do that in SQL yet. You could pass a delimited string and parse it over in your stored proc.
Can I use ALTER LOGIN in a stored procedure?
Can the ALTER USER statement be used (without a hack like using EXEC) in a stored procedure? I know that the sp_password system stored procedure can not be. Additionally, it is being deprecated anyway. I guess what is boggling me about my attempts so far relate to the errors I am getting due to the user being specified not being in quotes in the syntax. All of the searching I have done so far have come up lame so far; the only examples I have found about it were in scripts that create other scripts for transferring users and other administrative tasks that would be run from the query window, but not from an application. To be complete as possible, here is an example of a script the returns errors:
ALTER PROC [dbo].[lbxChangePassword]
(
@.loginid nvarchar(180),
@.oldpassword nvarchar(40),
@.newpassword nvarchar(40)
) AS BEGIN
IF @.oldpassword = (SELECT password FROM contacts WHERE loginid = @.loginid)
BEGIN
BEGIN TRANSACTION
UPDATE contacts
SET password = @.newpassword
WHERE loginid = @.loginid
ALTER LOGIN @.loginid WITH PASSWORD=@.newpassword OLD_PASSWORD=@.oldpassword
END
ELSE
BEGIN
RAISERROR(N'The password you entered does not match your current password.', 16, 1)
RETURN
END
IF @.@.ERROR <> 0
BEGIN
RAISERROR(N'There was an error creating your new password.', 16, 1)
RETURN
END
COMMIT TRANSACTION
END
************
This returns:
Msg 102, Level 15, State 1, Procedure lbxChangePassword, Line 15
Incorrect syntax near '@.loginid'.
Msg 319, Level 15, State 1, Procedure lbxChangePassword, Line 15
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
************
If ALTER LOGIN isn't how to change the password, then please tell me what the correct practice of changing a password is. I want to use the CURRENT_USER keyword in my queries and want I can't finish setting that up until I have this resolved because users will need to change their own passwords through the application I am developing.
I guess you have to put that in dynamic sql to execute:
DECLARE @.SQLStrng NVARCHAR(500)
SET @.SQLString = 'ALTER LOGIN ' + @.loginid + ' WITH PASSWORD= '' + @.newpassword + '' OLD_PASSWORD= '' + @.oldpassword + '''
EXEC(SQLString )
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
Yes, the DDL does not accept variables. If you build the string dynamically, use quotename() around the variable names to get them quoted properly:
DECLARE @.SQLStrng NVARCHAR(500)
SET @.SQLString = 'ALTER LOGIN ' + quotename(@.loginid) + ' WITH PASSWORD= ' + quotename(@.newpassword, '''') + ' OLD_PASSWORD= ' + quotename(@.oldpassword, '''')
EXEC(SQLString )
Thanks
Laurentiu
I'll try this, but I was hoping that there would be a way to do this without using a "hack".
Am I not approaching this the right way? The user will be logging into a PHP application and I need for them to be able to change their password. Would you recommend a stored procedure to accomplish this like the ones we've been writing about, or is there a best practice for this. I mean, otherwise how can one administer database users from a web app and still use SQL Server's security model? I don't understand Microsoft's reasoning in this architecture.
|||Writing a stored procedure to accomplish this is OK. If you don't like to build the dynamic SQL and execute it with EXEC, you might prefer using sp_executesql instead: http://msdn2.microsoft.com/en-US/library/ms175170(SQL.90).aspx.
Thanks
Laurentiu
Well, I read a post by a SQL Server MVP that said that another way to do this is to specify the old/new password in a connection string to the SQL Server Native Client. e.g.:
"Provider=SQLNCLI;Data Source=MyServer;User ID=MyLogin;Old Password=oldpassword;Password=password"
But I don't think PHP is friendly to connection strings though; I tried fiddling with ODBC connections in PHP with no luck. Has anyone heard anything about this?
|||Try posting on SQL Server Data Access for more details on the connection string idea. I think this connection string is probably meant to be used when a login password is expired; it is not the regular way of changing a login password. If you're looking at all possible ways of changing a login password, you should also check the SQL Server SMO/DMO forum - you could write a CLR procedure to perform this action (see .NET Framework inside SQL Server for questions on using CLR inside SQL Server).
Thanks
Laurentiu
I'm just a curious person :-) Thanks. Good Ideas.
-Ryan
Can I use a stored procedure for INSERT in SqlDataSource?
Hello,
I have created a web page with a FormView that allows me to add and edit data in my database. I configured the SqlDataSource control and it populated the SELECT, INSERT, UPDATE and DELETE statements. I've created a stored procedure to do the INSERT and return to new identity value. My question is this: Can I configure the control to use this stored procedure? If so, how? Or do I have to write some code for one of the event handlers (inserting, updating?)
Any help would be appreciated.
-brian
Yes you can. Not seeing your code makes it difficult to diagnose, but it sounds like you have the SqlDataSource partially set up. Make sure you also have the insertcommand attribute set to your new stored procedure and the insertcommandtype set to "StoredProcedure". The InsertParameters should also be set to include any input parameters that are not explicitly bound within the FormView.InsertItemTemplate.
From here, you need to make sure the FormView is in insert mode, your InsertItemTemplate is properly set up, and you have an insert button with the CommandName attribute properly set to "Insert".
Once you click that button, the FormView.ItemInserting event will fire, then the SqlDataSource.Inserting event will fire.
Assuming you have all of your stored procedure input parameters properly set up within your ASPX page, your stored procedure should run, and you can pick up your return parameter from the SqlDataSource.Inserted event.
Hope this helps.
can i use a store procedure as default value for a column?
Is it possible to use a stored procedure to fill the default value of a column when i'm building the db?
i mean if i can use a stored procedure for the "colum property": "default value or bnding"
if yes how can i do it?
No, you won't be able to specify a stored procedure in your table definition as a default value for a column. Your best bet for this is to set up a trigger (either AFTER or INSTEAD OF) to enforce the default value.
|||You can, however, use a scalar user-defined function as the default value. So if you can convert the sproc to a UDF or call it from one, you're good to go.
Don
Can I use a DataSet with 2 Tables in Reporting Services
create a new dataset using the stroed proc, I can only see Table[0]. Is it
possible to create a report using a DataSet with 2 tables such as this?
Thanks...Greyhound,
This is not possible. You have two choices;
1) Create two datasets in your report and split your stored proc up.
2) Union the results for each table into a single table and add a filter
field to filter the results in the report.
AK Code Rat
"Greyhound" wrote:
> I have created a DataSet with Table[0] and Table[1] in a stored proc. When I
> create a new dataset using the stroed proc, I can only see Table[0]. Is it
> possible to create a report using a DataSet with 2 tables such as this?
> Thanks...
Can I use 2 different stored procedure in a single report?
dataset? How so?I am not sure why would you want do do this but if you are after getting two
resultsets by executing the two stored procedures, RS doesn't support
multiple resultsets.If you just need to do some pre-processing with the
first stored procedure, consider wrapping the two stored procedures with a
third stored procedure.
--
HTH,
---
Teo Lachev, MVP, MCSD, MCT
"Microsoft Reporting Services in Action"
"Applied Microsoft Analysis Services 2005"
Home page and blog: http://www.prologika.com/
---
"MissQti" <MissQti@.discussions.microsoft.com> wrote in message
news:FDACE96D-69B7-41B7-A93B-4504C9332BBF@.microsoft.com...
> Can I use 2 different stored procedures in a single report with the same
> dataset? How so?
Friday, February 24, 2012
Can I start Excel on a PC using a Stored Procedure?
Thanks in advance,
RaulExcel is a desktop application. You cannot start applications that require
a GUI component from SQL Server... SQL Server Agent will hang.
What exactly are you trying to accomplish?
"Raul" <raul@.nothere.com> wrote in message
news:62AA65E5-C7A4-4B81-9BFC-5A1AC579BE42@.microsoft.com...
> Is there any way to have a job in SQL Server start Excel on a PC?
> Thanks in advance,
> Raul|||You could create a scheduled task on your PC, called Task1, which launches
Excel.
From the SQL server,
xp_cmdshell 'schtasks /run /tn Task1 /s NAMEOFPC'
In order for this to work the SQL server process must be running as a user
that has administrative authority on the PC on which you want to start Excel
.
(Starting a scheduled task remotely requires administrator priveledge). If i
t
is running under the local system account, you could specify a username and
password in the schtasks command:
xp_cmdshell 'schtasks /run /tn Task1 /s NAMEOFPC /u username /p password'
This way would put the password for an (administrative) account in plain
text somewhere, so it is not very secure.
"Raul" wrote:
> Is there any way to have a job in SQL Server start Excel on a PC?
> Thanks in advance,
> Raul|||I want a stored procedure, that is run as a scheduled job in SQL Server
Agent, to return the results of a query to a specific Excel workbook. Once
the data is inserted in the workbook, I would like to run a VBA routine in
the workbook to carry out a number of tasks.
I can write the results of the query in Excel using a linked server to the
desired spreadsheet, but I like to be able to fire off the routine to perfor
m
a number of desired tasks after the data has been inserted.
Raul
"Aaron Bertrand [SQL Server MVP]" wrote:
> Excel is a desktop application. You cannot start applications that requir
e
> a GUI component from SQL Server... SQL Server Agent will hang.
> What exactly are you trying to accomplish?
>
>
>
> "Raul" <raul@.nothere.com> wrote in message
> news:62AA65E5-C7A4-4B81-9BFC-5A1AC579BE42@.microsoft.com...
>
>|||Thanks a bunch! The biggest problem may be getting the IT folks to give me
administrator privileges on the server. I guess the other option is to add
a
new administrator account on my PC.
Thanks again,
Raul
"Mark Williams" wrote:
> You could create a scheduled task on your PC, called Task1, which launches
> Excel.
> From the SQL server,
> xp_cmdshell 'schtasks /run /tn Task1 /s NAMEOFPC'
> In order for this to work the SQL server process must be running as a user
> that has administrative authority on the PC on which you want to start Exc
el.
> (Starting a scheduled task remotely requires administrator priveledge). If
it
> is running under the local system account, you could specify a username an
d
> password in the schtasks command:
> xp_cmdshell 'schtasks /run /tn Task1 /s NAMEOFPC /u username /p password'
> This way would put the password for an (administrative) account in plain
> text somewhere, so it is not very secure.
> --
> "Raul" wrote:
>
can I specify timout for views/sp?
I have some queries in my sql 2000 server that need a long timout (>60
sec.). Is there a way to specify a timeout for a view or stored procedure
that returns a recordset?
Will the ADO Connection.CommandTimeout solve my problem (can I set this just
before executing the query)? MSDN tells me in Q190606 to use an
asynchrounous query for executing long time queries (because of a bug in the
Connection.CommandTimeout property), but my component is running in an ASP
application, so a timer to check the execution status is not really easy to
implement.
Thanks for your time,
SvenSven,
According to this KB note http://tinyurl.com/j23d you may need to use the
Command.CommandTimeout instead of the Connection.CommandTimeout. It says
"the Command object does not pickup the Connection's CommandTimeout
setting."
This is specific to a command issued from your application. There is no way
to set a timeout for a specific view or stored procedure.
Russell Fields
"Sven Erik Matzen" <sven.matzen@.dontspamme.com> wrote in message
news:ODf1KEyWDHA.1680@.tk2msftngp13.phx.gbl...
> Hi,
> I have some queries in my sql 2000 server that need a long timout (>60
> sec.). Is there a way to specify a timeout for a view or stored procedure
> that returns a recordset?
> Will the ADO Connection.CommandTimeout solve my problem (can I set this
just
> before executing the query)? MSDN tells me in Q190606 to use an
> asynchrounous query for executing long time queries (because of a bug in
the
> Connection.CommandTimeout property), but my component is running in an ASP
> application, so a timer to check the execution status is not really easy
to
> implement.
> Thanks for your time,
> Sven
>|||Will the Connection.CommandTimeout work when using the Recordset object with
the connection? I currently don't have a command object.
"Russell Fields" <rlfields@.sprynet.com> wrote in message
news:#1TfuC2WDHA.1384@.TK2MSFTNGP10.phx.gbl...
> Sven,
> According to this KB note http://tinyurl.com/j23d you may need to use the
> Command.CommandTimeout instead of the Connection.CommandTimeout. It says
> "the Command object does not pickup the Connection's CommandTimeout
> setting."
> This is specific to a command issued from your application. There is no
way
> to set a timeout for a specific view or stored procedure.
> Russell Fields
> "Sven Erik Matzen" <sven.matzen@.dontspamme.com> wrote in message
> news:ODf1KEyWDHA.1680@.tk2msftngp13.phx.gbl...
> > Hi,
> >
> > I have some queries in my sql 2000 server that need a long timout (>60
> > sec.). Is there a way to specify a timeout for a view or stored
procedure
> > that returns a recordset?
> >
> > Will the ADO Connection.CommandTimeout solve my problem (can I set this
> just
> > before executing the query)? MSDN tells me in Q190606 to use an
> > asynchrounous query for executing long time queries (because of a bug in
> the
> > Connection.CommandTimeout property), but my component is running in an
ASP
> > application, so a timer to check the execution status is not really easy
> to
> > implement.
> >
> > Thanks for your time,
> > Sven
> >
> >
>