Showing posts with label stored. Show all posts
Showing posts with label stored. Show all posts

Wednesday, March 28, 2012

No idea if this is the right place to post... Need stored proc help

Hello,
I am trying to make a stored proc that will tell me if there are any rows in a table. The table name is a variable that I get at the start of the proc it is not sent in. What I am looking for in the table is sent into the stored proc.

here is where the problem is, i can not save it. It does not seem to allow me to use the if exists with variables. I have tried it also without the + and with the + ' to create a string I cant seem to get it anyway I try.
if exists (SELECT * FROM + @.TableName + WHERE + @.ColumnName + = + @.SearchStr2)

print 'got here ' +@.TableName + ' '+ @.ColumnName

END

Thanks for any help

You need to build the entire query string in a variable, and then use the dbo.sp_executesql stored procedure to execute that query string. As you've discovered, you can't use 'if exists' with variables.

For example:

declare @.sql nvarchar(max)

set @.sql = N'

if exists (select * from ' + @.TableName + N' where ' + @.ColumnName + ' = ''' + @.SearchStr2 + ''')

print ''Got here ' + @.TableName + ', ' + @.ColumnName + ''''

exec dbo.sp_executesql @.sql

|||

All of this of course is true; however, you also need to know that this is exactly the style of code that a hacker is looking to exploit for an "SQL Injection" attack. Please do some additional research before you implement this. This kind of code CREATES a security hole.


Dave

|||

Thanks Iain I will give it a shot and let you know. Also thanks Mugambo but this is a one time thing i need to run to do the following if anyone has a better idea how to do it I would love ideas.

I need to update our SQL database for an individual user. The problem is somehow this user got two ID's with different numbers and it has been about 4 months now that it has gone unnoticed and. So I now need to change the two id's into one. So what I was planning to do was to do was search ever column of every table and it would let me know if there is an exact match to the ID I put in. If so it will display the column and table so I can decide if it is data I need to change or not. We have about 200 tables so to do it one table at a time wouldnt be impossible to do but this way I learn a little more about SQL and stored procs which is what I really want anyway.

Thanks again

|||And thanks again Iain works great.|||Hi,

Can you mark a correct answer for us please.

Thanks!

No formulas in Stored Procedure params?

Hi,
is there any reason why it is not allowed to use formulas as Stored
Procedure parameters?
e.g.: EXEC myProc(@.myVar + ' ' + @.myVar2)
I could make use of this feature over and over if SQL Server 2k would allow
me to.
Axel DahmenI believe this has to do with the way the compiler works. By the time
you've hit the EXEC, it's too late to evaluate the expression. But it's
really not too bad:
DECLARE @.myVar3 VARCHAR(300)
SET @.MyVar3 = @.myVar + ' ' + @.myVar2
EXEC myProc @.MyVar3
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"Axel Dahmen" <NO_SPAM@.NoOneKnows.invalid> wrote in message
news:uDecFY3PFHA.648@.TK2MSFTNGP14.phx.gbl...
> Hi,
> is there any reason why it is not allowed to use formulas as Stored
> Procedure parameters?
> e.g.: EXEC myProc(@.myVar + ' ' + @.myVar2)
> I could make use of this feature over and over if SQL Server 2k would
allow
> me to.
> Axel Dahmen
>|||Thanks, Adam.
I must admit that I'm not too satisfied with the current way of handling
this. I feel it's fairly awkward to write a bunch of lines like:
DECLARE @.myVar3 VARCHAR(300)
SET @.MyVar3 = @.myVar + ' ' + @.myVar2
EXEC myProc @.MyVar3
instead of just simply:
EXEC myProc @.myVar + ' ' + @.myVar2
particularly if you do things on-the-fly.
Do you perhaps know if SQL Server 2k5 will be able to process expressions in
procedure/UDF calls? If it doesn't, do you probably know about some channel
to suggest this functionality? It's nagging me for quite a while now. And
perhaps others might find a change in parsing procedure/UDF calls useful,
too.
Best wishes,
Axel
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> schrieb im
Newsbeitrag news:#5ZoPd3PFHA.3196@.TK2MSFTNGP12.phx.gbl...
> I believe this has to do with the way the compiler works. By the time
> you've hit the EXEC, it's too late to evaluate the expression. But it's
> really not too bad:
> DECLARE @.myVar3 VARCHAR(300)
> SET @.MyVar3 = @.myVar + ' ' + @.myVar2
> EXEC myProc @.MyVar3
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
> "Axel Dahmen" <NO_SPAM@.NoOneKnows.invalid> wrote in message
> news:uDecFY3PFHA.648@.TK2MSFTNGP14.phx.gbl...
> allow
>|||> I feel it's fairly awkward
But necessary, so what are you going to do?
A workaround would be dynamic SQL, but it becomes quite complex as you have
varying data types being passed to the stored procedure.

> Do you perhaps know if SQL Server 2k5 will be able to process expressions
> in
> procedure/UDF calls?
No.

> If it doesn't, do you probably know about some channel
> to suggest this functionality?
sqlwish@.microsoft.com

> It's nagging me for quite a while now. And
> perhaps others might find a change in parsing procedure/UDF calls useful,
> too.
Frankly, the known workarounds are really not all that cumbersome, and I
think most people have just learned to live with the limitation and have
moved on. This sounds like the same kind of problem we have when people use
SELECT * or otherwise try avoid "all the hard work" of typing out a column
list.
This is my signature. It is a general reminder.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.|||"Axel Dahmen" <NO_SPAM@.NoOneKnows.invalid> wrote in message
news:uOU1kA4PFHA.2604@.TK2MSFTNGP10.phx.gbl...
> Do you perhaps know if SQL Server 2k5 will be able to process expressions
in
> procedure/UDF calls? If it doesn't, do you probably know about some
channel
> to suggest this functionality? It's nagging me for quite a while now. And
> perhaps others might find a change in parsing procedure/UDF calls useful,
> too.
No, the behavior won't change in SS2005 (at least, not based on anything
I've heard, and I've also just tested on the latest build -- same behavior).
I believe -- although someone else can hopefully back me up on this as I
don't know for certain -- that the behavior complies to the ANSI standard.
And if the standard doesn't support that, I wouldn't expect SQL Server to.
As I said, it has to do with the way the compiler works. SQL is compiled
using a very simple single-pass method. Re-doing that compilation for the
sake of this feature is not really a good use of time. There are a few
other features that could be done with multi-pass compilation, but I don't
think the SQL Server team would agree with me on how interesting I think
some of them are ;)
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--

> Best wishes,
> Axel
>
> --
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> schrieb im
> Newsbeitrag news:#5ZoPd3PFHA.3196@.TK2MSFTNGP12.phx.gbl...
>|||I might be ignorant here, but even after giving it some deep thoughts I
don't find a reason why it should give the interpreter a hard time to accept
expressions instead of identifiers as procedure parameters.
The internal SQL Server part executing the SET statement could be used, for
instance, to interpret a given expression. The interpreter might create some
temporary dummy variable first to store the calculation result internally.
When calling a procedure/UDF a data type transformation call is triggered
internally for each parameter. So it's safe to assume that a parameter's
data format is already known to the interpreter. It should be easy then to
create such internal dummy variable to store the expression result and to
forward that result to the standard procedure/UDF call.
It would even be possible to have no additional execution costs compared to
the present (lacking)implementation. A cache could be implemented to hold
all temporary variables for the next call to the same procedure within the
same batch.
Program Flow:
- prepare procedure call
- WHILE parameter read
- if parameter is no legal identifier then
- create dummy variable to hold parameter
- SET {dummy variable} = parameter
- overwrite parameter to point to dummy variable
- add parameter to procedure call
- call procedure
RFC,
Axel Dahmen
www.sportbootcharter.com
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> schrieb im
Newsbeitrag news:#OH8lR4PFHA.2560@.TK2MSFTNGP14.phx.gbl...
> "Axel Dahmen" <NO_SPAM@.NoOneKnows.invalid> wrote in message
> news:uOU1kA4PFHA.2604@.TK2MSFTNGP10.phx.gbl...
expressions
> in
> channel
And
useful,
> No, the behavior won't change in SS2005 (at least, not based on
anything
> I've heard, and I've also just tested on the latest build -- same
behavior).
> I believe -- although someone else can hopefully back me up on this as I
> don't know for certain -- that the behavior complies to the ANSI standard.
> And if the standard doesn't support that, I wouldn't expect SQL Server to.
> As I said, it has to do with the way the compiler works. SQL is compiled
> using a very simple single-pass method. Re-doing that compilation for the
> sake of this feature is not really a good use of time. There are a few
> other features that could be done with multi-pass compilation, but I don't
> think the SQL Server team would agree with me on how interesting I think
> some of them are ;)
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
it's
would
>|||>> I might be ignorant here, but even after giving it some deep
thoughts I don't find a reason why it should give the interpreter a
hard time to accept expressions instead of identifiers as procedure
parameters. <<
In the early days of Sybase/SQL Server, we had a rule that you never
wrote over one page of T-SQL in a stored procedure or a trigger. It
was a kludge to get around the lack of DRI actions, DEFAULT, CHECK(),
etc, back in the Stone Age. It was never meant to be a full language.
The truth is that T-SQL was an early, one-pass compiler based on C; it
was not meant to do Thunks. One -pass compilers have a hell of a time
with Thunks; it takes two passes in most cases. Today T-SQL would be a
one-quarter senior project using a Compiler compiler, YACC or whatever.
Full strength application development languages came later. The
Informix 4GL isbased on the Algol family and a lot of mainframe
packages use it under the covers; it generated ANSI Standard C and is
very portable, has a report writer, etc. Progress started as a nice
application development 4GL which added SQL. PL/SQL in Oracle and the
Standard SQL/PSM are both based on ADA.
What we need is the Standard SQL/PSM instead of the CLR crap that is
about to destroy SQL Server databases (I have some anti-CLR rants
posted in various places).|||> The truth is that T-SQL was an early, one-pass compiler based on C; it
> was not meant to do Thunks. One -pass compilers have a hell of a time
> with Thunks; it takes two passes in most cases.
I appreciate that. But the SET command is already able do it. Thus I assume
the only change in procedure call processing should basically be to call the
SET command part after reading a parameter token. Perhaps there even is a
general expression parser part available in the interpreter that can be used
by T-SQL language coders at MS.
My main assumption is that:
if the T-SQL interpreter can process this (manual) sequence in one pass
DECLARE @.var ...
SET @.var = {expression}
EXEC proc @.var
then it can also do this automatically itself.
The most simple (and farmost worst) option would be to just expand any
parameter call to the above sequence internally. This deduction is my proof
of concept.

> What we need is the Standard SQL/PSM instead of the CLR crap that is
> about to destroy SQL Server databases (I have some anti-CLR rants
> posted in various places).
That's another story, but you're right, I agree with you. Giving too much
programming power to SQL Server will probably lead into decadence in design
in terms of a multi-tier model. And I'm also apprehensive of SQL Server 2005
becoming a slow performer and thus less scalable. Any Framework,
particularly .NET and Java by its nature of using IL, is slow and clumsy.
Well, it's a matter of consideration between RAD and performance. But enough
OT... ;)
Axel|||>> if the T-SQL interpreter can process this (manual) sequence in one
pass ... then it can also do this automatically itself. <<
Did you take a compiler writing course in college? I taught one :)
The simple ase is easy; the general case is a bear!
The compiler has to catch the general expression in the parameter,
adjust the scope of the declarations, fill in parameters in any
function calls, recursive function calls, self-references, etc. It
is not a simple matter of replacing a marker with "((<< expression
T-SQL sets error flags one statement at a time; SQL/PSM and modern
languages set multiple errors all at once based on BEGIN ATOMIC .. END
blocks. T-SQL was never meant for "industrial usage" in a modern
programming environment.|||> One -pass compilers have a hell of a time
> with Thunks; it takes two passes in most cases.
It took a few moments for me to see what you mean... The trick would be to
assume a destination data type to store the expression result in.
I guess there will be a feasible solution to that. For instance, every
expression calculated by SQL Server has an intrinsic data type. During
interpretation of the SET command the result is probably forwarded to the
data type converter part after calculation of the expression result. To
create a matching temporary memory space (or variable), this step ought to
be injected in between:
Assumed Standard SET Command Program Flow:
1) read destination variable
2) lookup destination variable in memory
3) read expression to be assigned
4) calculate expression
5) forward expression result and destination variable to
data type converter in order to store the converted
result into destination variable
To allow for dynamic destination variable creation, the flow could be
interjected with something like (one additional step added):
1) read expression to be assigned
2) calculate expression
* 3) create temporary destination variable from expression
data type
4) forward expression result and destination variable to
data type converter in order to store the converted
result into destination variable
5) provide destination variable to stored procedure
parameter
Regards,
Axel

No exception message from CLR stored procedure

Hello everybody,

I've encountered a strange thing using a CLR Stored procedure:

The procedure throws an exception with no message inside... value = {" "}

Basically the procedure has a string as argument which contains a SQL statement that changes according to the users selections...

The results of the query are saved into a dataset for further processing.

Those resultsets can sometimes be very big (ex: 15000 records...). (For the record the procedure works fine for smaller datasets ex 6000 records and running the same query on the application server returns the expected resultset )

By Debugging the procedure I could determine that the failing point was when the dataset is filled...

Anyone having any idea?

The only information I have from this exception is the stacktrace:

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)

at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

at System.Data.SqlClient.SqlDataReader.CloseInternal(Boolean closeReader)

at System.Data.SqlClient.SqlDataReader.Close()

at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

at System.Data.SqlClient.SqlCommand.ExecuteScalar()

at DataAccess.runScalar(String strSQL, Boolean isStoredProcedure) in c:\Inetpub\wwwroot\Statistix\App_Code\DataAccess.cs:line 114

Thanks in advance

Alaindlk

Hello,

Still nobody having any idea of what is happening here?

Could it be possible that the SQL server is running out of memory or even having a connection timeout?

this is the procedure I've written that causes this behaviour:

[Microsoft.SqlServer.Server.SqlProcedure]

public static int Stats_Print_Data(string SqlQuery)

{

// Put your code here

int jobId = -1;

using (DataSet dsResults = new DataSet())

{

using (SqlConnection mConn = new SqlConnection("context connection = true"))

{

SqlCommand mCmd = new SqlCommand(SqlQuery, mConn);

mCmd.CommandTimeout = 100;

SqlDataAdapter mDa = new SqlDataAdapter(mCmd);

mDa.Fill(dsResults, "Print_Data");

if (dsResults.Tables[0].Rows.Count > 0)

{

ArrayList ColumnNames = new ArrayList();

for (int i = 8; i < dsResults.Tables[0].Columns.Count; i++)

{

DataColumn dc = dsResults.Tables[0].ColumnsIdea;

ColumnNames.Add(dc.ColumnName);

}

StringBuilder InsertCommand = new StringBuilder();

StringBuilder Values = new StringBuilder();

try

{

mConn.Open();

mCmd.CommandText = "Select max(report_id) from Statistix_Report";

jobId = System.Convert.ToInt16(mCmd.ExecuteScalar());

jobId++;

foreach (DataRow dr in dsResults.Tables[0].Rows)

{

if (InsertCommand.Length > 0) InsertCommand.Remove(0, InsertCommand.Length);

if (Values.Length > 0) Values.Remove(0, Values.Length);

mCmd.CommandText = "Select count(*) from print_data where AG_LIB = '" + dr[2].ToString().Replace("'", "''") +

"' and AN_LIB = '" + dr[3].ToString().Replace("'", "''") + "' and PRD_LIB = '" + dr[4].ToString().Replace("'", "''") +

"' and TM_LIB = '" + dr[5].ToString().Replace("'", "''") + "' and RM_LIB = '" + drDevil.ToString().Replace("'", "''") +

"' and SU_LIB = '" + dr[7].ToString().Replace("'", "''") + "'";

if (System.Convert.ToInt16(mCmd.ExecuteScalar()) > 0)

{

InsertCommand.Append("Update PRINT_DATA set ");

for (int i = 0; i < ColumnNames.Count; i++)

{

InsertCommand.Append(ColumnNamesIdea + "_" + int.Parse(dr["Month"].ToString()) + " = ");

if (dr[i + 8] != DBNull.Value)

{

InsertCommand.Append(dr[i + 8].ToString().Replace(",", "."));

}

else

{

InsertCommand.Append("0");

}

if (i != ColumnNames.Count - 1)

{

InsertCommand.Append(",");

}

}

InsertCommand.Append(" where AG_LIB = '" + dr[2].ToString().Replace("'", "''"));

InsertCommand.Append("' and AN_LIB = '" + dr[3].ToString().Replace("'", "''") + "' and PRD_LIB = '" + dr[4].ToString().Replace("'", "''"));

InsertCommand.Append("' and TM_LIB = '" + dr[5].ToString().Replace("'", "''") + "' and RM_LIB = '" + drDevil.ToString().Replace("'", "''"));

InsertCommand.Append("' and SU_LIB = '" + dr[7].ToString().Replace("'", "''") + "' and JOB_ID = " + jobId);

mCmd.CommandText = InsertCommand.ToString();

mCmd.ExecuteNonQuery();

}

else

{

Values = new StringBuilder();

InsertCommand = new StringBuilder();

InsertCommand.Append("insert into print_data(AG_LIB,AN_LIB,PRD_LIB,TM_LIB,RM_LIB,SU_LIB,JOB_ID,");

Values.Append("'" + dr[2].ToString().Replace("'", "''") + "','" + dr[3].ToString().Replace("'", "''") + "','");

Values.Append(dr[4].ToString().Replace("'", "''") + "','" + dr[5].ToString().Replace("'", "''") + "','");

Values.Append(drDevil.ToString().Replace("'", "''") + "','" + dr[7].ToString().Replace("'", "''") + "'," + jobId + ",");

for (int i = 0; i < ColumnNames.Count; i++)

{

InsertCommand.Append(ColumnNamesIdea + "_" + int.Parse(dr["Month"].ToString()));

if (dr[i + 8] != DBNull.Value)

{

Values.Append(dr[i + 8].ToString().Replace(",", "."));

}

else Values.Append("0");

if (i != ColumnNames.Count - 1)

{

InsertCommand.Append(",");

Values.Append(",");

}

}

InsertCommand.Append(") values (");

InsertCommand.Append(Values.ToString() + ")");

mCmd.CommandText = InsertCommand.ToString();

mCmd.ExecuteNonQuery();

}

}

}

catch (Exception ex)

{

throw new Exception(InsertCommand.ToString(), ex);

}

finally

{

mCmd.Dispose();

mConn.Close();

}

}

}

}

return jobId;

}

Any help would be greatly appreciated...

How can i debug something like this?

Thanks in advance

|||

Are you sure that it is the error message thrown by SqlClient is empty and not the exception you throw here:

catch (Exception ex)

{

throw new Exception(InsertCommand.ToString(), ex);

}

? What happens if you remove this catch block and let the unhandled exception get propogated back to sql server - is it still empty?

|||

Hello Steven,

Thanks for your reply...

The exception I've given above is effectively thrown by the stored procedure...

Further investigation learned me that it was indeed a timeout of the stored procedure, so I deed improve the indexing on the tables which now solves partly my problem...

However The problem still remains as the stored procedure, after fetching the required data, saves this data into a table for reporting. The problem is that each 12 rows in the dataset has to be transformed as one record with 12 columns (Table sucks but I have to work with this solution imposed to me ) This means I first need to know if the record already exists, if not then create an insert statement else create an update statement.
Now it seems that executing this causes a timeout for the procedure.
Is there any way to increase this timeout period?

|||

Hello everybody,

I think I've finally found the reason why this timeout occurs: Thats because of the fact that the stored procedure returns a value...
In the worst case, my procedure takes about 10 minutes to complete.... letting the Application server waiting that long is "unacceptable". I think that SQL server automatically throws a timeout exception whenever a procedure/ function takes to long to complete.
I've solved this by changing the procedure signature from Static int SP_Name to static void SP_name(); This way the procedure doesn't have to return a value and isn't any more interrupted by a timeout thrown by SQL server...

Can anyone confirm me this behaviour of SQL server? (By the way this solution works fine for me now...)

Thanks in advance

Monday, March 26, 2012

No Display Output using Stored Procedure

I call a stored procedure from the RS Data area and all data is retrieved on
the browse area when I run the procedure in the data window. I have
manually listed all fields in the Dataset->Fields window and drag them into
the Layout screen.
When I try to preview the report it seems to load the rows (ie 7 pages are
shown as loaded) but doesn't display any data, only the headings show with
and blank body section. If a put a string literal in one field it appears
on each row of the report but all other fields are blank.
I've looked through Output Options without any joy...Could you please post the rdl and ddl for a stored procedure that goes
against any of the sample databases so I can investigate?
--
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"spamh8ers" <spamh8ers@.discussions.microsoft.com> wrote in message
news:2C2EC175-8681-42F9-A398-CAF83DEE765C@.microsoft.com...
> Does anyone have a solution for this yet? I have similar issues with
> creating new reports. If I start the the report with text query like
Select
> SalesOrder from SalesOrders, the report runs with no problem but when I
> change to a stored procedure, I get pages of empty report body.
> Ideas or workarounds?
> "news.microsoft.com" wrote:
> > I call a stored procedure from the RS Data area and all data is
retrieved on
> > the browse area when I run the procedure in the data window. I have
> > manually listed all fields in the Dataset->Fields window and drag them
into
> > the Layout screen.
> >
> > When I try to preview the report it seems to load the rows (ie 7 pages
are
> > shown as loaded) but doesn't display any data, only the headings show
with
> > and blank body section. If a put a string literal in one field it
appears
> > on each row of the report but all other fields are blank.
> >
> > I've looked through Output Options without any joy...
> >
> >
> >

No dependencies when inserting data into a #temp table

Hi
I have a problem. I have a database with way to many stored procedures. In
order delete some i made a script that finds stored procedures and their
dependencies. Those without any dependencies should be deleted because they
typically have been emptied for logic.
But unfortunately if there is a 'INSERT INTO #TEMP (FIELD1) SELECT Field1
FROM TABLE_1' there is no dependency for table TABLE_1. If the INSERT INTO
uses a normal table or a table variable there is a dependency.
My example below turns out to have no dependecies as all even though the
table exists up front and the procedure has been executed succesfully.
Example: --
CREATE PROCEDURE Test3 AS
Create Table #no (
i int
)
Insert into #no (i) Select top 10 ID from table_1
Select * from #no
Drop table #no
--
This is a problem for me because a lot of my reports collect data from
several tables and insert them into temp tables. But effectively they will
show up with no dependencies and therefor be subject for deletion.
Remodelling all stored procedures to use table variables is no option.
This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error in
the product or whether there is a good reason for doing as it does.> This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error
> in
> the product or whether there is a good reason for doing as it does.
One of the reasons dependency information may be missing is due to deferred
name resolution. Since the temp table does not exist when the proc is
created, no dependency info is recorded for any objects referenced by the
INSERT statement.

> Remodelling all stored procedures to use table variables is no option.
If you create the temp table before creating the proc, you should get the
dependency info.

> This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error
> in
> the product or whether there is a good reason for doing as it does.
Although one could make the argument that this is a bug, it's unclear to me
what the correct behavior should be when a statement contains a mix of
existing and non-existing objects. You might consider submitting product
enhancement feedback via Connect (http://connect.microsoft.com/SQLServer) to
suggest that known dependency information be recorded when a statement
contains a mix of existing and non-existing objects. Perhaps this will make
it into the next SQL Server version or future service pack.
Hope this helps.
Dan Guzman
SQL Server MVP
"Karsten Feddersen, Denmark" <Karsten Feddersen,
Denmark@.discussions.microsoft.com> wrote in message
news:48D61C0B-5635-4137-A3E8-C7A7CC16796F@.microsoft.com...
> Hi
> I have a problem. I have a database with way to many stored procedures. In
> order delete some i made a script that finds stored procedures and their
> dependencies. Those without any dependencies should be deleted because
> they
> typically have been emptied for logic.
> But unfortunately if there is a 'INSERT INTO #TEMP (FIELD1) SELECT Field1
> FROM TABLE_1' there is no dependency for table TABLE_1. If the INSERT INTO
> uses a normal table or a table variable there is a dependency.
> My example below turns out to have no dependecies as all even though the
> table exists up front and the procedure has been executed succesfully.
> Example: --
> CREATE PROCEDURE Test3 AS
> Create Table #no (
> i int
> )
> Insert into #no (i) Select top 10 ID from table_1
> Select * from #no
> Drop table #no
> --
> This is a problem for me because a lot of my reports collect data from
> several tables and insert them into temp tables. But effectively they will
> show up with no dependencies and therefor be subject for deletion.
> Remodelling all stored procedures to use table variables is no option.
> This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error
> in
> the product or whether there is a good reason for doing as it does.sql

No dependencies when inserting data into a #temp table

Hi
I have a problem. I have a database with way to many stored procedures. In
order delete some i made a script that finds stored procedures and their
dependencies. Those without any dependencies should be deleted because they
typically have been emptied for logic.
But unfortunately if there is a 'INSERT INTO #TEMP (FIELD1) SELECT Field1
FROM TABLE_1' there is no dependency for table TABLE_1. If the INSERT INTO
uses a normal table or a table variable there is a dependency.
My example below turns out to have no dependecies as all even though the
table exists up front and the procedure has been executed succesfully.
Example: --
CREATE PROCEDURE Test3 AS
Create Table #no (
i int
)
Insert into #no (i) Select top 10 ID from table_1
Select * from #no
Drop table #no
--
This is a problem for me because a lot of my reports collect data from
several tables and insert them into temp tables. But effectively they will
show up with no dependencies and therefor be subject for deletion.
Remodelling all stored procedures to use table variables is no option.
This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error in
the product or whether there is a good reason for doing as it does.> This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error
> in
> the product or whether there is a good reason for doing as it does.
One of the reasons dependency information may be missing is due to deferred
name resolution. Since the temp table does not exist when the proc is
created, no dependency info is recorded for any objects referenced by the
INSERT statement.
> Remodelling all stored procedures to use table variables is no option.
If you create the temp table before creating the proc, you should get the
dependency info.
> This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error
> in
> the product or whether there is a good reason for doing as it does.
Although one could make the argument that this is a bug, it's unclear to me
what the correct behavior should be when a statement contains a mix of
existing and non-existing objects. You might consider submitting product
enhancement feedback via Connect (http://connect.microsoft.com/SQLServer) to
suggest that known dependency information be recorded when a statement
contains a mix of existing and non-existing objects. Perhaps this will make
it into the next SQL Server version or future service pack.
Hope this helps.
Dan Guzman
SQL Server MVP
"Karsten Feddersen, Denmark" <Karsten Feddersen,
Denmark@.discussions.microsoft.com> wrote in message
news:48D61C0B-5635-4137-A3E8-C7A7CC16796F@.microsoft.com...
> Hi
> I have a problem. I have a database with way to many stored procedures. In
> order delete some i made a script that finds stored procedures and their
> dependencies. Those without any dependencies should be deleted because
> they
> typically have been emptied for logic.
> But unfortunately if there is a 'INSERT INTO #TEMP (FIELD1) SELECT Field1
> FROM TABLE_1' there is no dependency for table TABLE_1. If the INSERT INTO
> uses a normal table or a table variable there is a dependency.
> My example below turns out to have no dependecies as all even though the
> table exists up front and the procedure has been executed succesfully.
> Example: --
> CREATE PROCEDURE Test3 AS
> Create Table #no (
> i int
> )
> Insert into #no (i) Select top 10 ID from table_1
> Select * from #no
> Drop table #no
> --
> This is a problem for me because a lot of my reports collect data from
> several tables and insert them into temp tables. But effectively they will
> show up with no dependencies and therefor be subject for deletion.
> Remodelling all stored procedures to use table variables is no option.
> This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error
> in
> the product or whether there is a good reason for doing as it does.

No dependencies when inserting data into a #temp table

Hi
I have a problem. I have a database with way to many stored procedures. In
order delete some i made a script that finds stored procedures and their
dependencies. Those without any dependencies should be deleted because they
typically have been emptied for logic.
But unfortunately if there is a 'INSERT INTO #TEMP (FIELD1) SELECT Field1
FROM TABLE_1' there is no dependency for table TABLE_1. If the INSERT INTO
uses a normal table or a table variable there is a dependency.
My example below turns out to have no dependecies as all even though the
table exists up front and the procedure has been executed succesfully.
Example: --
CREATE PROCEDURE Test3 AS
Create Table #no (
i int
)
Insert into #no (i)Select top 10 ID from table_1
Select * from #no
Drop table #no
This is a problem for me because a lot of my reports collect data from
several tables and insert them into temp tables. But effectively they will
show up with no dependencies and therefor be subject for deletion.
Remodelling all stored procedures to use table variables is no option.
This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error in
the product or whether there is a good reason for doing as it does.
> This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error
> in
> the product or whether there is a good reason for doing as it does.
One of the reasons dependency information may be missing is due to deferred
name resolution. Since the temp table does not exist when the proc is
created, no dependency info is recorded for any objects referenced by the
INSERT statement.

> Remodelling all stored procedures to use table variables is no option.
If you create the temp table before creating the proc, you should get the
dependency info.

> This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error
> in
> the product or whether there is a good reason for doing as it does.
Although one could make the argument that this is a bug, it's unclear to me
what the correct behavior should be when a statement contains a mix of
existing and non-existing objects. You might consider submitting product
enhancement feedback via Connect (http://connect.microsoft.com/SQLServer) to
suggest that known dependency information be recorded when a statement
contains a mix of existing and non-existing objects. Perhaps this will make
it into the next SQL Server version or future service pack.
Hope this helps.
Dan Guzman
SQL Server MVP
"Karsten Feddersen, Denmark" <Karsten Feddersen,
Denmark@.discussions.microsoft.com> wrote in message
news:48D61C0B-5635-4137-A3E8-C7A7CC16796F@.microsoft.com...
> Hi
> I have a problem. I have a database with way to many stored procedures. In
> order delete some i made a script that finds stored procedures and their
> dependencies. Those without any dependencies should be deleted because
> they
> typically have been emptied for logic.
> But unfortunately if there is a 'INSERT INTO #TEMP (FIELD1) SELECT Field1
> FROM TABLE_1' there is no dependency for table TABLE_1. If the INSERT INTO
> uses a normal table or a table variable there is a dependency.
> My example below turns out to have no dependecies as all even though the
> table exists up front and the procedure has been executed succesfully.
> Example: --
> CREATE PROCEDURE Test3 AS
> Create Table #no (
> i int
> )
> Insert into #no (i) Select top 10 ID from table_1
> Select * from #no
> Drop table #no
> --
> This is a problem for me because a lot of my reports collect data from
> several tables and insert them into temp tables. But effectively they will
> show up with no dependencies and therefor be subject for deletion.
> Remodelling all stored procedures to use table variables is no option.
> This occurs in both SQL 2000 and SQL 2005 so I wonder if this is an error
> in
> the product or whether there is a good reason for doing as it does.

Friday, March 23, 2012

No columns defined in rowset

Hello Experts,
I have a stored procedure. I used ADO to called this stored procedure. In
runtime, it says "No columns defined in rowset".
Here is my stored procedure:
========================================
========
CREATE PROCEDURE [sp_MigrateAccount]
@.i_vchSessionID VARCHAR(50),
@.o_intRetVal int OUTPUT
AS
-- Variables for error handling.
DECLARE @.intError int
DECLARE @.insAcct_error int
DECLARE @.insAcctSum_error int
DECLARE @.insAddr_error int
DECLARE @.drop_error int
DECLARE @.intRecordErrorCounter int
-- Temporary storage
DECLARE @.chSourceAccountID char(12)
DECLARE @.vchSourceAccount char(128)
DECLARE @.vchSourceMainPhone char(32)
DECLARE @.vchSourceFax char(32)
DECLARE @.chSourceUserfield5 char(80)
DECLARE @.m_cintMigrateSucceed int
DECLARE @.m_cintRecordDataError int
DECLARE @.m_cintInsertToRealTableError int
DECLARE @.m_cintDuplicateKeyError int
SET NOCOUNT ON
-- Assign value to constants
SET @.m_cintMigrateSucceed = 0
SET @.m_cintRecordDataError = 2
SET @.m_cintInsertToRealTableError = 3
SET @.m_cintDuplicateKeyError = 7
-- Perform data validation --
-- Check for duplicate ACCOUNTID
SET @.intRecordErrorCounter = 0
SELECT @.intRecordErrorCounter = COUNT (a1.ACCOUNTID)
FROM sysdba.ACCOUNT AS a1
WHERE a1.ACCOUNTID IN
(SELECT ACCOUNTID
FROM ACCOUNT_TEMP
WHERE SessionID = @.i_vchSessionID)
IF (@.intRecordErrorCounter > 0) -- There exists at least one validation
error.
BEGIN
-- Update ErrorColumn in the source table. --
-- 1 is an arbitrary value for the ErrorColumn.
-- If ErrorColumn is NULL or 0, this record has no error.
UPDATE sysdba.ACCOUNT_TEMP
SET ErrorColumn = @.m_cintDuplicateKeyError
WHERE (SessionID = @.i_vchSessionID)
AND ACCOUNTID IN
(SELECT ACCOUNTID
FROM ACCOUNT)
-- No need to update the destination table, thus we quit the SP
-- Note that the error number used by SQL Server is greater than 0.
SET @.intError = @.m_cintDuplicateKeyError
GOTO Quit_SP
END
-- Up to this point, the data validation is passed.
-- We can insert record into the destination table. now.
BEGIN TRAN dataMigration
-- Insert records to the ACCOUNT table
-- People from newsgroup said that you are required to
-- enter uppercase Account Name into ACCOUNT_UC field.
INSERT INTO ACCOUNT
(ACCOUNTID, ACCOUNT, MAINPHONE, FAX, [DESCRIPTION], SECCODEID,
ADDRESSID, SHIPPINGID, ACCOUNTMANAGERID, CREATEUSER, MODIFYUSER,
CREATEDATE,
MODIFYDATE, ACCOUNT_UC)
SELECT ACCOUNTID, ACCOUNT, MAINPHONE, FAX, [DESCRIPTION], SECCODEID,
ADDRESSID, SHIPPINGID, ACCOUNTMANAGERID, CREATEUSER, MODIFYUSER,
CREATEDATE,
MODIFYDATE, ACCOUNT_UC
FROM sysdba.ACCOUNT_TEMP
WHERE SessionID = @.i_vchSessionID
SET @.insAcct_error = @.@.ERROR
IF (0 = @.insAcct_error) BEGIN
COMMIT TRAN dataMigration
END
ELSE
BEGIN
IF (0 <> @.insAcct_error)
-- Const m_cintInsertToRealTableError = 3
SET @.intError = @.m_cintInsertToRealTableError
ROLLBACK TRAN dataMigration
END
Error_Handler:
Quit_SP:
IF (@.intError IS NULL)
-- No value assigned to @.intError in the
-- body of this stored procedure.
-- Thus, migrate data is successful.
-- Const m_cintMigrateSucceed = 0
SET @.o_intRetVal = @.m_cintMigrateSucceed
ELSE
SET @.o_intRetVal = @.intError -- Failure encountered.
RETURN
GO
========================================
=
Here is my VBScript that used ADO to call the store procedure:
========================================
===
' :
' ADO database connection....
' :
With ADOCmd
.CommandText = "sp_MigrateAccount"
.CommandType = adCmdStoredProc
strInputText = i_strSessionID
lngParamLen = Len(strInputText)
If lngParamLen <= 0 Then
lngParamLen = 1
End If
Set ADOParam = .CreateParameter("@.i_vchType", adVarChar,
adParamInput, lngParamLen, strInputText)
.Parameters.Append ADOParam
Set ADOParam = .CreateParameter("@.o_intRetVal", adInteger,
adParamOutput)
.Parameters.Append ADOParam
Set .ActiveConnection = objCon
.Execute
lngRetVal = .Parameters("@.o_intRetVal").Value
End With
' :
' :
' :
'=======================================
==
The ".Execute" statement caused the "No columns defined in rowset".
If I try the following statement:
.Execute , , (adCmdStoredProc Or adExecuteNoRecords)
Or,
.Execute , , adExecuteNoRecords
I cannot get the output value (@.o_intRetVal) from the stored procedure.
May I know how to solve this problem? Thanks a lot.
SammySa wrote:
> Hello Experts,
> I have a stored procedure. I used ADO to called this stored
> procedure. In runtime, it says "No columns defined in rowset".
That does not sound like an ADO error. It sounds more like a T-SQL error.
ADO errors usually refer to recordsets, fields and records. "rowset" makes
it sound
like a T-SQL error.
Have you verified that this procedure runs correctly in Query Analyzer? Like
this:
declare @.ret int
exec sp_MigrateAccount 'some session id',@.ret output
select @.ret [Output Value]

> Here is my stored procedure:
> ========================================
========
> CREATE PROCEDURE [sp_MigrateAccount]
Nothing to do with your error, but using "sp_" for a non-system stored
procedure can cause a slight performance dip, since the query engine treats
all procedures beginning with this prefix as system procedures, looking for
them first in Master, and only looking for them in the current database when
it fails to find them in Master. If you mistakenly name your procedure the
same as a real system procedure, you've got a knotty debugging problem ahead
of you ...

> @.i_vchSessionID VARCHAR(50),
> @.o_intRetVal int OUTPUT
> AS
> -- Variables for error handling.
> DECLARE @.intError int
<snip>
> SET NOCOUNT ON
I doubt this is the problem, but I generally make this the first statement
in my procedures - before any other statement, even DECLARE's.

>
<snip>
> ========================================
=
>
> Here is my VBScript that used ADO to call the store procedure:
> ========================================
===
> ' :
> ' ADO database connection....
> ' :
> With ADOCmd
> .CommandText = "sp_MigrateAccount"
> .CommandType = adCmdStoredProc
> strInputText = i_strSessionID
> lngParamLen = Len(strInputText)
> If lngParamLen <= 0 Then
> lngParamLen = 1
> End If
> Set ADOParam = .CreateParameter("@.i_vchType", adVarChar,
> adParamInput, lngParamLen, strInputText)
> .Parameters.Append ADOParam
> Set ADOParam = .CreateParameter("@.o_intRetVal",
> adInteger, adParamOutput)
> .Parameters.Append ADOParam
> Set .ActiveConnection = objCon
> .Execute
> lngRetVal = .Parameters("@.o_intRetVal").Value
> End With
> ' :
> ' :
> ' :
> '=======================================
==
> The ".Execute" statement caused the "No columns defined in rowset".
> If I try the following statement:
> .Execute , , (adCmdStoredProc Or adExecuteNoRecords)
Should be:
.Execute , , (adCmdStoredProc + adExecuteNoRecords)
HTH,
Bob Barrows
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.sql

Tuesday, March 20, 2012

no "properties" option on stored procedures (cant set permissions)

SQL 2005 express.
I detached an SQL 2005 express database from server A and attached to SQL
2005 express on server B.
When i right click stored procedure from server A i see a PROPERITES
options.
When i do the same from server B ..... NO PROPERTIES option is available.
I view the SPs in both DBs using SQL Express Mgt studio. Both managers are
logged in as SA.
Any ideas ?
Thank
Scott
---
http://www.sage-eshop.comJust a wild guess:
Perhaps the owner of the database isn't a login on server B? See sp_changedbowner.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Scott" <http://www.sage-eshop.com> wrote in message news:uommvsq9GHA.2268@.TK2MSFTNGP05.phx.gbl...
> SQL 2005 express.
> I detached an SQL 2005 express database from server A and attached to SQL
> 2005 express on server B.
> When i right click stored procedure from server A i see a PROPERITES
> options.
> When i do the same from server B ..... NO PROPERTIES option is available.
> I view the SPs in both DBs using SQL Express Mgt studio. Both managers are
> logged in as SA.
> Any ideas ?
> Thank
> Scott
> ---
> http://www.sage-eshop.com
>|||thanks for reply.
i can see sp_changedbowner, it executes ok.
im not exactly sure what i should do with it now.
scott.|||My guess is that the owner for the database (the SID) doesn't exist as a login in the master
database. Try setting the owner to sa, for instance.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Scott" <http://www.sage-eshop.com> wrote in message
news:uF%233%23Hr9GHA.4012@.TK2MSFTNGP04.phx.gbl...
> thanks for reply.
> i can see sp_changedbowner, it executes ok.
> im not exactly sure what i should do with it now.
> scott.
>|||i created a new DB and new SP and still dont get the properties.
if the user has the ability to create a DB and SPs in the db, they should
have the ability to view/amend properties.|||Might be a bug in the GUI you are using. If you are using the express version of management studio,
you might want to post to an express group. I didn't find such on this news server, but you can try
the HTTP groups:
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=385&SiteID=1
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Scott" <http://www.sage-eshop.com> wrote in message news:et40aRr9GHA.3352@.TK2MSFTNGP03.phx.gbl...
>i created a new DB and new SP and still dont get the properties.
> if the user has the ability to create a DB and SPs in the db, they should have the ability to
> view/amend properties.
>|||Hi ..
I'm getting exactly the same issue.. We've gone and created our
databases in SQL Express, but have a code generator that needs to look
at extended proeprties on the stored procedures. In SQL Express
databases, the Properties option is not available for SP's,
Personally I just think this is a bug in the Management Studio UI too,
as Properties is available for the other objects such as Tables,
Databases (do it's not that SQL Express doesn't supoprt Extended
Properties, which was my first guess).
If you get any luck, please post a message here.
Scott wrote:
> i created a new DB and new SP and still dont get the properties.
> if the user has the ability to create a DB and SPs in the db, they should
> have the ability to view/amend properties.

Monday, March 12, 2012

NH: Best Practices Approach - call stored proc - or run it via linked server?

what pro's cons would there be to having a linked server run a local stored proc against another sql server or create that stored proc on that other sql server and call it from there in the c# code.

i would think that calling the stored proc would be more efficient that running a linked server - but please let me know your thoughts. I'm not sure i can have permission to add a stored proc on that server, so possibly the linked server is the only solution - but if i can put a stored proc on that server should i?

thanks.

Jeff

anyone?|||

One obvious thing to keep in mind is the performance. Depending on your network the executiion time could be different.

Now I am not sure if I understand your question. If you do not have permission to create the stored proc on the original server you would still need access to the underlying tables if you want to access them through server B, irrespective of whether its via stored proc or directly T-SQL.

|||

well typically I associate using a linked server to pull data from something using openquery such as ibm as400 so my question is do i get access to put the stored proc on the remote sql server (not one of my groups sql servers), or do i ask for setting up a linked server to it and execute the stored proc from my local sql server using the linked server approach.

either way?
get access to put the stored proc right on the sql server and call it in c#?
use the linked server and call it in c#

Just looking for some reason why one way may be better than another, primarily performance, and reducing putting in another possible point of failure.

thanks,

JB

|||

info@.learnbartending.com:

Just looking for some reason why one way may be better than another, primarily performance, and reducing putting in another possible point of failure.

Those are exactly the reasons why you might want to put the proc directly where the data is.

Friday, March 9, 2012

Next Object id already assigned

I originally posted this problem under "stored proc won't compile" in
the programming group, but now that I've found more detail, I think it
is better suited to this group with a different title.
I can't create any objects in master. What I've found is that the
dbi_nextid is already assigned to another object. Can anyone offer
any suggestions? DBCC checkcatalog and dbcc checkdb return no errors.
create proc simpleproc as select * from sysobjects
returns
Server: Msg 2714, Level 16, State 5, Procedure simpleproc, Line 1
There is already an object named 'simpleproc' in the database.
Further research has found the the dbi_nextid is already in use.
DBCC TRACEON(3604)
DBCC DBINFO('master')
DBCC TRACEOFF(3604)
returns
dbi_nextid = 1537440551
select name, type, id, crdate from sysobjects where id = 1537440551
returns
name type id crdate
sp_dropmergearticleP 15374405512003-03-09 18:00:50.177
select max(id) from master.dbo.sysobjects
returns
2145442717
@.@.version =
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Enterprise Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
> Server: Msg 2714, Level 16, State 5, Procedure simpleproc, Line 1
> There is already an object named 'simpleproc' in the database.
>
> Further research has found the the dbi_nextid is already in use.
Why did you go further? It appears you already have a procedure named
simpleproc, and this is why you can't create another one. How about change
the name to splungeproc and see if that works. Why are you creating these
procs in master anyway? How many objects are in master now?
http://www.aspfaq.com/
(Reverse address to reply.)
|||I went further because I need to get the proc created. It is an SMTP
mail proc that I ultimately need to create. I used the simpleproc
example so people would not have to wade through lines of code. I am
sure simpleproc does not exist
My problem is I can't create any object in master - regardless of the
name or type. Tables, views, stored procs all receive the same error -
object already exists. If I try and drop the object first, I get that
it does not exist.
select * from sysobjects where name = 'simpleproc'
go
drop proc dbo.simpleproc
go
create proc dbo.simpleproc as select * from sysobjects
returns
(0 row(s) affected)
Server: Msg 3701, Level 11, State 5, Line 3
Cannot drop the procedure 'dbo.simpleproc', because it does not exist in
the system catalog.
Server: Msg 2714, Level 16, State 5, Procedure simpleproc, Line 1
There is already an object named 'simpleproc' in the database.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
|||What about my other questions? Why does this have to be in master? How
many objects are in master now?
http://www.aspfaq.com/
(Reverse address to reply.)
"Stephanie Harrell" <stephanie.harrell@.stateauto.com> wrote in message
news:uA3PgWCaEHA.2840@.TK2MSFTNGP11.phx.gbl...
> I went further because I need to get the proc created. It is an SMTP
> mail proc that I ultimately need to create. I used the simpleproc
> example so people would not have to wade through lines of code. I am
> sure simpleproc does not exist
|||A count of sysobjects returns 1305.
I am putting the proc in master because on all my other servers it is in
master. This is an enterprise wide proc developed for standard use in
sending emails from SQL. I don't want it to be in master on all the
other servers and a different database on this one. In hindsight, we
might have made this an extended stored proc, but there is too much code
to go back and change it now.
But all that is really beside the point. I should be able to create
objects in master - whether it is advisable or not - and I can't because
the "next object id" is already being used.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
|||This sounds like a known issue - please call Product Support who will assist
you.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Stephanie Harrell" <stephanie.harrell@.stateauto.com> wrote in message
news:u2A3XnCaEHA.3996@.TK2MSFTNGP12.phx.gbl...
> A count of sysobjects returns 1305.
> I am putting the proc in master because on all my other servers it is in
> master. This is an enterprise wide proc developed for standard use in
> sending emails from SQL. I don't want it to be in master on all the
> other servers and a different database on this one. In hindsight, we
> might have made this an extended stored proc, but there is too much code
> to go back and change it now.
> But all that is really beside the point. I should be able to create
> objects in master - whether it is advisable or not - and I can't because
> the "next object id" is already being used.
>
> *** Sent via Devdex http://www.devdex.com ***
> Don't just participate in USENET...get rewarded for it!
|||Thank you Paul!!
Since you mentioned a known problem, I found KB Article
http://support.microsoft.com/default...48&Product=sql
And it did the trick. I could not get the supplied script to work, so
I simple coded a drop and create and duplicated the lines 50 or so
times. Then ran that until the object created successfully.
Thanks again
"Paul S Randal [MS]" <prandal@.online.microsoft.com> wrote in message news:<e0onLTHaEHA.3888@.TK2MSFTNGP10.phx.gbl>...[vbcol=seagreen]
> This sounds like a known issue - please call Product Support who will assist
> you.
> --
> Paul Randal
> Dev Lead, Microsoft SQL Server Storage Engine
> This posting is provided "AS IS" with no warranties, and confers no rights.
> "Stephanie Harrell" <stephanie.harrell@.stateauto.com> wrote in message
> news:u2A3XnCaEHA.3996@.TK2MSFTNGP12.phx.gbl...

Next Object id already assigned

I originally posted this problem under "stored proc won't compile" in
the programming group, but now that I've found more detail, I think it
is better suited to this group with a different title.
I can't create any objects in master. What I've found is that the
dbi_nextid is already assigned to another object. Can anyone offer
any suggestions? DBCC checkcatalog and dbcc checkdb return no errors.
create proc simpleproc as select * from sysobjects
returns
Server: Msg 2714, Level 16, State 5, Procedure simpleproc, Line 1
There is already an object named 'simpleproc' in the database.
Further research has found the the dbi_nextid is already in use.
DBCC TRACEON(3604)
DBCC DBINFO('master')
DBCC TRACEOFF(3604)
returns
dbi_nextid = 1537440551
select name, type, id, crdate from sysobjects where id = 1537440551
returns
name type id crdate
sp_dropmergearticle P 1537440551 2003-03-09 18:00:50.177
select max(id) from master.dbo.sysobjects
returns
2145442717
@.@.version =
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Enterprise Edition on Windows NT 5.0 (Build 2195: Service Pack 4)> Server: Msg 2714, Level 16, State 5, Procedure simpleproc, Line 1
> There is already an object named 'simpleproc' in the database.
>
> Further research has found the the dbi_nextid is already in use.
Why did you go further? It appears you already have a procedure named
simpleproc, and this is why you can't create another one. How about change
the name to splungeproc and see if that works. Why are you creating these
procs in master anyway? How many objects are in master now?
--
http://www.aspfaq.com/
(Reverse address to reply.)

Next Object id already assigned

I originally posted this problem under "stored proc won't compile" in
the programming group, but now that I've found more detail, I think it
is better suited to this group with a different title.
I can't create any objects in master. What I've found is that the
dbi_nextid is already assigned to another object. Can anyone offer
any suggestions? DBCC checkcatalog and dbcc checkdb return no errors.
create proc simpleproc as select * from sysobjects
returns
Server: Msg 2714, Level 16, State 5, Procedure simpleproc, Line 1
There is already an object named 'simpleproc' in the database.
Further research has found the the dbi_nextid is already in use.
DBCC TRACEON(3604)
DBCC DBINFO('master')
DBCC TRACEOFF(3604)
returns
dbi_nextid = 1537440551
select name, type, id, crdate from sysobjects where id = 1537440551
returns
name type id crdate
sp_dropmergearticle P 1537440551 2003-03-09 18:00:50.177
select max(id) from master.dbo.sysobjects
returns
2145442717
@.@.version =
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Enterprise Edition on Windows NT 5.0 (Build 2195: Service Pack 4)> Server: Msg 2714, Level 16, State 5, Procedure simpleproc, Line 1
> There is already an object named 'simpleproc' in the database.
>
> Further research has found the the dbi_nextid is already in use.
Why did you go further? It appears you already have a procedure named
simpleproc, and this is why you can't create another one. How about change
the name to splungeproc and see if that works. Why are you creating these
procs in master anyway? How many objects are in master now?
http://www.aspfaq.com/
(Reverse address to reply.)|||I went further because I need to get the proc created. It is an SMTP
mail proc that I ultimately need to create. I used the simpleproc
example so people would not have to wade through lines of code. I am
sure simpleproc does not exist
My problem is I can't create any object in master - regardless of the
name or type. Tables, views, stored procs all receive the same error -
object already exists. If I try and drop the object first, I get that
it does not exist.
select * from sysobjects where name = 'simpleproc'
go
drop proc dbo.simpleproc
go
create proc dbo.simpleproc as select * from sysobjects
returns
(0 row(s) affected)
Server: Msg 3701, Level 11, State 5, Line 3
Cannot drop the procedure 'dbo.simpleproc', because it does not exist in
the system catalog.
Server: Msg 2714, Level 16, State 5, Procedure simpleproc, Line 1
There is already an object named 'simpleproc' in the database.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!|||What about my other questions? Why does this have to be in master? How
many objects are in master now?
http://www.aspfaq.com/
(Reverse address to reply.)
"Stephanie Harrell" <stephanie.harrell@.stateauto.com> wrote in message
news:uA3PgWCaEHA.2840@.TK2MSFTNGP11.phx.gbl...
> I went further because I need to get the proc created. It is an SMTP
> mail proc that I ultimately need to create. I used the simpleproc
> example so people would not have to wade through lines of code. I am
> sure simpleproc does not exist|||A count of sysobjects returns 1305.
I am putting the proc in master because on all my other servers it is in
master. This is an enterprise wide proc developed for standard use in
sending emails from SQL. I don't want it to be in master on all the
other servers and a different database on this one. In hindsight, we
might have made this an extended stored proc, but there is too much code
to go back and change it now.
But all that is really beside the point. I should be able to create
objects in master - whether it is advisable or not - and I can't because
the "next object id" is already being used.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!|||This sounds like a known issue - please call Product Support who will assist
you.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Stephanie Harrell" <stephanie.harrell@.stateauto.com> wrote in message
news:u2A3XnCaEHA.3996@.TK2MSFTNGP12.phx.gbl...
> A count of sysobjects returns 1305.
> I am putting the proc in master because on all my other servers it is in
> master. This is an enterprise wide proc developed for standard use in
> sending emails from SQL. I don't want it to be in master on all the
> other servers and a different database on this one. In hindsight, we
> might have made this an extended stored proc, but there is too much code
> to go back and change it now.
> But all that is really beside the point. I should be able to create
> objects in master - whether it is advisable or not - and I can't because
> the "next object id" is already being used.
>
> *** Sent via Devdex http://www.devdex.com ***
> Don't just participate in USENET...get rewarded for it!|||Thank you Paul!!
Since you mentioned a known problem, I found KB Article
http://support.microsoft.com/defaul...448&Product=sql
And it did the trick. I could not get the supplied script to work, so
I simple coded a drop and create and duplicated the lines 50 or so
times. Then ran that until the object created successfully.
Thanks again
"Paul S Randal [MS]" <prandal@.online.microsoft.com> wrote in message news:<e0onLTHaEHA.3
888@.TK2MSFTNGP10.phx.gbl>...[vbcol=seagreen]
> This sounds like a known issue - please call Product Support who will assi
st
> you.
> --
> Paul Randal
> Dev Lead, Microsoft SQL Server Storage Engine
> This posting is provided "AS IS" with no warranties, and confers no rights
.
> "Stephanie Harrell" <stephanie.harrell@.stateauto.com> wrote in message
> news:u2A3XnCaEHA.3996@.TK2MSFTNGP12.phx.gbl...

Wednesday, March 7, 2012

News / Article Application Storage

Hi,

I'm building a straightforward-ish news site. Currently, the story details (e.g. headline, description, author, date) are stored in a SQL DB. The news is categorised and the category details are also stored in an SQL table.

However - what is the best way to store the actual news article?

At the moment, when the user enters a story, they input the details and article text. The details are saved in the DB and the text is saved as an XML file with filename corresponding to the article DB primary key. When the story is "read" the app pulls the details from the DB and loads up the appropriate XML file from disk.

For various reasons, I need to keep the article stored as XML, either in a file or in the DB. The DB provides for faster sorting and retrieval, and I don't want to store large amounts of data (i.e. the article itself) in the DB if avoidable.

I guess there are a few ways to do it -

1. Store details in DB and article as XML file.
2. Store details and article in same DB table
3. Store details in one DB table and articles in another

I would imagine that 3 would be the best, but would there be a performance hit? What is the maximum size of field (i.e. article size) I can have in a table?

Cheers

Graham Wilson.

I'm using choice 2 in my application.

In DB design, there is no need to use different tables for fields that can be in one table.

HTH
Regards

|||

OK, thanks.

My reasoning behind using two tables was because I was unsure if having a lot of data in one table would slow down any retrieval or searching?

|||

pipelineconsulting:

OK, thanks.

My reasoning behind using two tables was because I was unsure if having a lot of data in one table would slow down any retrieval or searching?

I don't think that will do any performance changes.

Newly created stored procedure => master db

I have upgraded my SQLExpress to SP1 but since doing this I am not able to
create stored procedures under the database that I created. It seems as if
any new procs are created in the master database.
If I create a new proc, it is not displayed under the stored procedure
folder. Iit is displayed in the folder c:\mydocuments\SQL ServerManagement
Studio Express\Projects along with the other procs that I'd created prior to
the upgrade.
If I open the newly created proc then I'm asked to login to the SQL Express
again (I already have Management Studio Express open and logged in to my own
database). Once the proc is open , the combo box "available databases" on the
toolbar displayes, 'master'. So it seems I've logged in to the master
database where the new proc has been created. But it is not displayed in the
Stored Procs of the master either.
What has gone wrong? I should be able to create new stored procs in my
database and not in the master database.
Can someone help - thanksLisa
What is happenening if you issue?
USE mydb
GO
CREATE PROC mmmm
AS
....
"Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
>I have upgraded my SQLExpress to SP1 but since doing this I am not able to
> create stored procedures under the database that I created. It seems as if
> any new procs are created in the master database.
> If I create a new proc, it is not displayed under the stored procedure
> folder. Iit is displayed in the folder c:\mydocuments\SQL ServerManagement
> Studio Express\Projects along with the other procs that I'd created prior
> to
> the upgrade.
> If I open the newly created proc then I'm asked to login to the SQL
> Express
> again (I already have Management Studio Express open and logged in to my
> own
> database). Once the proc is open , the combo box "available databases" on
> the
> toolbar displayes, 'master'. So it seems I've logged in to the master
> database where the new proc has been created. But it is not displayed in
> the
> Stored Procs of the master either.
> What has gone wrong? I should be able to create new stored procs in my
> database and not in the master database.
> Can someone help - thanks|||Thanks for your response. Unfortunately it makes no difference. I created the
new proc and then opened it, but the Connect to Database Engine dialog box is
displayed and I connect to the master db.
"Uri Dimant" wrote:
> Lisa
> What is happenening if you issue?
> USE mydb
> GO
> CREATE PROC mmmm
> AS
> .....
>
> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
> news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
> >I have upgraded my SQLExpress to SP1 but since doing this I am not able to
> > create stored procedures under the database that I created. It seems as if
> > any new procs are created in the master database.
> >
> > If I create a new proc, it is not displayed under the stored procedure
> > folder. Iit is displayed in the folder c:\mydocuments\SQL ServerManagement
> > Studio Express\Projects along with the other procs that I'd created prior
> > to
> > the upgrade.
> >
> > If I open the newly created proc then I'm asked to login to the SQL
> > Express
> > again (I already have Management Studio Express open and logged in to my
> > own
> > database). Once the proc is open , the combo box "available databases" on
> > the
> > toolbar displayes, 'master'. So it seems I've logged in to the master
> > database where the new proc has been created. But it is not displayed in
> > the
> > Stored Procs of the master either.
> >
> > What has gone wrong? I should be able to create new stored procs in my
> > database and not in the master database.
> > Can someone help - thanks
>
>|||Lisa
Ok, it is by default. You can change it by using
EXEC sp_defaultdb 'Lisa', 'AdventureWorks'
"Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
news:16DB04B0-8E9B-4C8C-88FD-F881A31AA781@.microsoft.com...
> Thanks for your response. Unfortunately it makes no difference. I created
> the
> new proc and then opened it, but the Connect to Database Engine dialog box
> is
> displayed and I connect to the master db.
>
> "Uri Dimant" wrote:
>> Lisa
>> What is happenening if you issue?
>> USE mydb
>> GO
>> CREATE PROC mmmm
>> AS
>> .....
>>
>> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in
>> message
>> news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
>> >I have upgraded my SQLExpress to SP1 but since doing this I am not able
>> >to
>> > create stored procedures under the database that I created. It seems as
>> > if
>> > any new procs are created in the master database.
>> >
>> > If I create a new proc, it is not displayed under the stored procedure
>> > folder. Iit is displayed in the folder c:\mydocuments\SQL
>> > ServerManagement
>> > Studio Express\Projects along with the other procs that I'd created
>> > prior
>> > to
>> > the upgrade.
>> >
>> > If I open the newly created proc then I'm asked to login to the SQL
>> > Express
>> > again (I already have Management Studio Express open and logged in to
>> > my
>> > own
>> > database). Once the proc is open , the combo box "available databases"
>> > on
>> > the
>> > toolbar displayes, 'master'. So it seems I've logged in to the master
>> > database where the new proc has been created. But it is not displayed
>> > in
>> > the
>> > Stored Procs of the master either.
>> >
>> > What has gone wrong? I should be able to create new stored procs in my
>> > database and not in the master database.
>> > Can someone help - thanks
>>|||Uri
I don't want to seem ignorant but where do I use this. I'm using Access as
my front end and SQLExpress as the backend. :(
Also - I'm not able to modify any of the previous stored procs. If I make a
modification and save by overwriting the proc, the changes are not there when
I open the proc again.
"Uri Dimant" wrote:
> Lisa
> Ok, it is by default. You can change it by using
> EXEC sp_defaultdb 'Lisa', 'AdventureWorks'
> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
> news:16DB04B0-8E9B-4C8C-88FD-F881A31AA781@.microsoft.com...
> > Thanks for your response. Unfortunately it makes no difference. I created
> > the
> > new proc and then opened it, but the Connect to Database Engine dialog box
> > is
> > displayed and I connect to the master db.
> >
> >
> > "Uri Dimant" wrote:
> >
> >> Lisa
> >> What is happenening if you issue?
> >> USE mydb
> >> GO
> >> CREATE PROC mmmm
> >> AS
> >> .....
> >>
> >>
> >> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in
> >> message
> >> news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
> >> >I have upgraded my SQLExpress to SP1 but since doing this I am not able
> >> >to
> >> > create stored procedures under the database that I created. It seems as
> >> > if
> >> > any new procs are created in the master database.
> >> >
> >> > If I create a new proc, it is not displayed under the stored procedure
> >> > folder. Iit is displayed in the folder c:\mydocuments\SQL
> >> > ServerManagement
> >> > Studio Express\Projects along with the other procs that I'd created
> >> > prior
> >> > to
> >> > the upgrade.
> >> >
> >> > If I open the newly created proc then I'm asked to login to the SQL
> >> > Express
> >> > again (I already have Management Studio Express open and logged in to
> >> > my
> >> > own
> >> > database). Once the proc is open , the combo box "available databases"
> >> > on
> >> > the
> >> > toolbar displayes, 'master'. So it seems I've logged in to the master
> >> > database where the new proc has been created. But it is not displayed
> >> > in
> >> > the
> >> > Stored Procs of the master either.
> >> >
> >> > What has gone wrong? I should be able to create new stored procs in my
> >> > database and not in the master database.
> >> > Can someone help - thanks
> >>
> >>
> >>
>
>

Newly created stored procedure => master db

I have upgraded my SQLExpress to SP1 but since doing this I am not able to
create stored procedures under the database that I created. It seems as if
any new procs are created in the master database.
If I create a new proc, it is not displayed under the stored procedure
folder. Iit is displayed in the folder c:\mydocuments\SQL ServerManagement
Studio Express\Projects along with the other procs that I'd created prior to
the upgrade.
If I open the newly created proc then I'm asked to login to the SQL Express
again (I already have Management Studio Express open and logged in to my own
database). Once the proc is open , the combo box "available databases" on th
e
toolbar displayes, 'master'. So it seems I've logged in to the master
database where the new proc has been created. But it is not displayed in the
Stored Procs of the master either.
What has gone wrong? I should be able to create new stored procs in my
database and not in the master database.
Can someone help - thanksLisa
What is happenening if you issue?
USE mydb
GO
CREATE PROC mmmm
AS
....
"Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
>I have upgraded my SQLExpress to SP1 but since doing this I am not able to
> create stored procedures under the database that I created. It seems as if
> any new procs are created in the master database.
> If I create a new proc, it is not displayed under the stored procedure
> folder. Iit is displayed in the folder c:\mydocuments\SQL ServerManagement
> Studio Express\Projects along with the other procs that I'd created prior
> to
> the upgrade.
> If I open the newly created proc then I'm asked to login to the SQL
> Express
> again (I already have Management Studio Express open and logged in to my
> own
> database). Once the proc is open , the combo box "available databases" on
> the
> toolbar displayes, 'master'. So it seems I've logged in to the master
> database where the new proc has been created. But it is not displayed in
> the
> Stored Procs of the master either.
> What has gone wrong? I should be able to create new stored procs in my
> database and not in the master database.
> Can someone help - thanks|||Thanks for your response. Unfortunately it makes no difference. I created th
e
new proc and then opened it, but the Connect to Database Engine dialog box i
s
displayed and I connect to the master db.
"Uri Dimant" wrote:

> Lisa
> What is happenening if you issue?
> USE mydb
> GO
> CREATE PROC mmmm
> AS
> .....
>
> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in messag
e
> news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
>
>|||Lisa
Ok, it is by default. You can change it by using
EXEC sp_defaultdb 'Lisa', 'AdventureWorks'
"Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
news:16DB04B0-8E9B-4C8C-88FD-F881A31AA781@.microsoft.com...[vbcol=seagreen]
> Thanks for your response. Unfortunately it makes no difference. I created
> the
> new proc and then opened it, but the Connect to Database Engine dialog box
> is
> displayed and I connect to the master db.
>
> "Uri Dimant" wrote:
>|||Uri
I don't want to seem ignorant but where do I use this. I'm using Access as
my front end and SQLExpress as the backend.
Also - I'm not able to modify any of the previous stored procs. If I make a
modification and save by overwriting the proc, the changes are not there whe
n
I open the proc again.
"Uri Dimant" wrote:

> Lisa
> Ok, it is by default. You can change it by using
> EXEC sp_defaultdb 'Lisa', 'AdventureWorks'
> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in messag
e
> news:16DB04B0-8E9B-4C8C-88FD-F881A31AA781@.microsoft.com...
>
>

Newboe: table containing XML schemas in database

I just created a schema in the AdventureWorks DB (the place for newbies). Where are these schemas stored and what t-sql statement can list all XML Schemas defined in a database\table\column?

TIA,

Barkingdog

select x.name, t.name, c.name
from sys.column_xml_schema_collection_usages cx,
sys.tables t,
sys.columns c,
sys.xml_schema_collections x
where x.xml_collection_id = cx.xml_collection_id
and t.object_id = cx.object_id
and c.column_id = cx.column_id
and c.object_id = t.object_id

The best way to learn this (catalog views) is thru SQL Server Management Studio -> Object Explorer -> Database -> master -> Views -> System views. Just do select * from every one of them.

Saturday, February 25, 2012

Newbie: stored procedure stops and exits prematurely

Well thanks to a lot of reading and experimentation, as a newbie, I've made
it to stored procedure writing...But my inexperience is showing, I'm
afraid...Can anyone point out what I should be doing here? Thank you...
I'm pulling several steps together into one stored procedure, but the
procedure stops and exits at the first step in order to return a message box
that says "The stored procedure executed successfully but did not return
records."
How can I tell the SP to continue to execute? Or, how can I avoid getting
the message?
Synopsis of the SP:
The purpose is to allow the user to select individuals to receive an
emailing. (The SP is called from the form.) Before presenting the list of
contacts on the form, I want to make sure that any new contacts in the
Contacts table get added to the SelectForEmail table . (The Contacts table
is part of a replicated database, to which I cannot add a trigger.)
Step 1: Behind the scenes, add any new contacts to the table SelectForEmail.
Step 2: Present the form that allows the user to check off the individuals
that should receive the emailing.
Here's the code for the first step:
/* Get all contacts from the contacts table */
INSERT INTO dbo.SelectForEmail (Contact_ID)
SELECT dbo.Contacts.Contact_ID FROM dbo.Contacts
LEFT OUTER JOIN dbo.SelectForEmail
ON dbo.Contacts.Contact_ID = dbo.SelectForEmail.Contact_ID
WHERE (dbo.SelectForEmail.Contact_ID IS NULL)> How can I tell the SP to continue to execute? Or, how can I avoid getting
> the message?
Perhaps the Procedure already executed but you didnt issued a command to
display any data ?
Create procedure DisplaySomeData
AS
INSERT INTO sometable values (1)
GO
--> Wont display any data
Create procedure DisplaySomeData
AS
INSERT INTO sometable values (1)
Select * from Sometable where ID = 1
GO
--> Will display data
It hard to tell what you have to do without having some of the DDL of your
procedure, please post some DDL and thatll try to help us to help you.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Kaycee Heyer" <heyerk@.uncw.edu> schrieb im Newsbeitrag
news:uISPrHKVFHA.3252@.TK2MSFTNGP10.phx.gbl...
> Well thanks to a lot of reading and experimentation, as a newbie, I've
> made
> it to stored procedure writing...But my inexperience is showing, I'm
> afraid...Can anyone point out what I should be doing here? Thank you...
> I'm pulling several steps together into one stored procedure, but the
> procedure stops and exits at the first step in order to return a message
> box
> that says "The stored procedure executed successfully but did not return
> records."
> How can I tell the SP to continue to execute? Or, how can I avoid getting
> the message?
> Synopsis of the SP:
> The purpose is to allow the user to select individuals to receive an
> emailing. (The SP is called from the form.) Before presenting the list of
> contacts on the form, I want to make sure that any new contacts in the
> Contacts table get added to the SelectForEmail table . (The Contacts table
> is part of a replicated database, to which I cannot add a trigger.)
> Step 1: Behind the scenes, add any new contacts to the table
> SelectForEmail.
> Step 2: Present the form that allows the user to check off the individuals
> that should receive the emailing.
> Here's the code for the first step:
>
> /* Get all contacts from the contacts table */
> INSERT INTO dbo.SelectForEmail (Contact_ID)
> SELECT dbo.Contacts.Contact_ID FROM dbo.Contacts
> LEFT OUTER JOIN dbo.SelectForEmail
> ON dbo.Contacts.Contact_ID = dbo.SelectForEmail.Contact_ID
> WHERE (dbo.SelectForEmail.Contact_ID IS NULL)
>|||Thanks.
I found that if I do the SELECT first, and then check @.@.ROWCOUNT <> 0
before doing the INSERT, that I can avoid getting the message.
Here's the entire new procedure:
ALTER PROCEDURE SEGM_EmailSelect4List
AS
/* Add new contacts from the contacts table */
/* Check first to make sure that new contacts exist */
SELECT dbo.Contacts.Contact_ID
FROM dbo.Contacts LEFT OUTER JOIN
dbo.SEGM_SelectForEmail ON
dbo.Contacts.Contact_ID = dbo.SEGM_SelectForEmail.Contact_ID
WHERE (dbo.SEGM_SelectForEmail.Contact_ID IS NULL)
IF @.@.ROWCOUNT <> 0
BEGIN
/* Add new contacts from the contacts table */
INSERT INTO dbo.SEGM_SelectForEmail
(Contact_ID)
SELECT dbo.Contacts.Contact_ID
FROM dbo.Contacts LEFT OUTER JOIN
dbo.SEGM_SelectForEmail ON
dbo.Contacts.Contact_ID = dbo.SEGM_SelectForEmail.Contact_ID
WHERE (dbo.SEGM_SelectForEmail.Contact_ID IS NULL)
END
/* Flag any contacts who have been investigators (that is, they exist in
the Investigators table) */
UPDATE dbo.SEGM_SelectForEmail
SET SEGM_Investigator = 1, SelectForEmail = 1
WHERE (Contact_ID IN
(SELECT dbo.Investigators.Contact_ID
FROM dbo.Investigators))
/* Return all contacts to the form that called us */
SELECT TOP 100 PERCENT dbo.Contacts.Last_Name,
dbo.Contacts.First_Name, dbo.Contacts.E_mail,
dbo.SEGM_SelectForEmail.SEGM_Investigator,
dbo.SEGM_SelectForEmail.SelectForEmail,
dbo.Affiliations.Affiliation
FROM dbo.Contacts
INNER JOIN dbo.SEGM_SelectForEmail ON
dbo.Contacts.Contact_ID = dbo.SEGM_SelectForEmail.Contact_ID
INNER JOIN dbo.Organizations ON dbo.Contacts.Organization_ID =
dbo.Organizations.Organization_ID
INNER JOIN dbo.Affiliations ON dbo.Organizations.Affiliation_ID =
dbo.Affiliations.Affiliation_ID
WHERE 1=1
ORDER BY dbo.Contacts.Last_Name, dbo.Contacts.First_Name
But now I have a new problem. The last select returns 0 rows to the form
opened in datasheet view. When I remove all the code except the last
select, it returns many rows.
What's going on?
*** Sent via Developersdex http://www.examnotes.net ***

Monday, February 20, 2012

newbie: logging for stored procs

ok when debugging a stored proc, yes i can see print output etc in sql
query analyzer. but when the proc is called in production, i dont see that
output; moreover, im new and wondering what are the typical ways that you
all log stuff from a stored proc, etc.
is something like this common?
http://www.databasejournal.com/feat...cle.php/1467591jimbo-black wrote:
> ok when debugging a stored proc, yes i can see print output etc in sql
> query analyzer. but when the proc is called in production, i dont
> see that output; moreover, im new and wondering what are the typical
> ways that you all log stuff from a stored proc, etc.
> is something like this common?
> http://www.databasejournal.com/feat...cle.php/1467591
Presumably, you have PRINT statements in procedures while they are in
development for debugging purposes and those PRINT statements are
removed for production. If what you need is a parameter-driven method to
execute a procedure with logging, then you can use conditional
statements in the procedure to log to a table as the article explains
(or even issue PRINT statements for interactive testing). In general,
though, it's better to do this type of work in development and keep your
procedure code to a minimum. For batch routines that might need to log
their lengthly processes and progress, a logging table would be the way
to go.
David Gugick
Quest Software
www.imceda.com
www.quest.com

newbie: logging for stored procs

ok when debugging a stored proc, yes i can see print output etc in sql
query analyzer. but when the proc is called in production, i dont see that
output; moreover, im new and wondering what are the typical ways that you
all log stuff from a stored proc, etc.
is something like this common?
http://www.databasejournal.com/features/mssql/article.php/1467591jimbo-black wrote:
> ok when debugging a stored proc, yes i can see print output etc in sql
> query analyzer. but when the proc is called in production, i dont
> see that output; moreover, im new and wondering what are the typical
> ways that you all log stuff from a stored proc, etc.
> is something like this common?
> http://www.databasejournal.com/features/mssql/article.php/1467591
Presumably, you have PRINT statements in procedures while they are in
development for debugging purposes and those PRINT statements are
removed for production. If what you need is a parameter-driven method to
execute a procedure with logging, then you can use conditional
statements in the procedure to log to a table as the article explains
(or even issue PRINT statements for interactive testing). In general,
though, it's better to do this type of work in development and keep your
procedure code to a minimum. For batch routines that might need to log
their lengthly processes and progress, a logging table would be the way
to go.
--
David Gugick
Quest Software
www.imceda.com
www.quest.com