Tagged Questions
3
votes
0answers
40 views
SELECT COL_NAME(969262708, ORDINAL_POSITION) returns a NULL value in one of the rows
So I've got a Stored Procedure that's copying data from one table to another. It calls this other SP to get the column names. I didn't write this darn thing, but here's that part:
ALTER PROCEDURE ...
0
votes
1answer
117 views
Stored Procedure Create Table from Variable with Variable Constraint
I have managed use a store procedure to create a copy of a table with a variable name. But I am struggling to understand how to incorporate a constraint into the stored procedure.
The problem:
The ...
3
votes
5answers
230 views
Stored Procedures under Source Control, best practice
I am currently using Tortoise SVN to source control a .NET Web Application. What would be the best way to bring our SQL Server stored procedures into Source Control? I am currently using VS 2010 as my ...
4
votes
1answer
140 views
Join To a @Table Variable is running ineficiently
Alright so I have a report sproc that was running incredibly slow. Customers were complaining that the report would not run so I started investigating exactly where in the sproc the problem was and I ...
5
votes
3answers
205 views
Create procedure in else block on SQL Server
I have a SQL script in which I generate a database and its tables, stored procedures, views, etc. I have used following script to generate the database and all the things.
I was able to generate ...
4
votes
1answer
124 views
Stored procedure performance metrics
I am taking over a new project which is having ~2500 SPs! and would like to know at current state what is the maximum / minimum time taken by each of the stored procs. Also IO, Logical Reads used by ...
1
vote
0answers
82 views
Requesting advice on creating a table controlled SQL job scheduler
I have been tasked with cleaning up a series of SQL jobs that send email updates about various data and system conditions in my company. Currently, there are a ton of jobs, each with its own SQL code ...
1
vote
1answer
213 views
How can I restore the sql_variant_property of baseType back to a table variable in SQL Server
Ok, I know the title is confusing but here it goes. BTW I am using SQL Server 2008
I have a table that I am trying to use as a storage container. It has 3 columns:
reportID integer,
dataLabel ...
5
votes
2answers
1k views
Separate stored procedures for inserts and updates?
I have a table in Microsoft SQL Server. Sometimes I need to update, and sometimes I need to insert. I could write 2 stored procedures:
InsertNewPerson
UpdatePertsonById
But I was thinking to write ...
2
votes
1answer
153 views
Only a single WITH MOVE clause should be specified for any logical file name
I'm trying to do a copy database by scripting a backup and restore. I have the backup procedure working correctly but I keep getting the error
Conflicting file relocations have been specified ...
3
votes
1answer
200 views
“Thread was being aborted” error when inserting 25k rows
I need to store about 25k rows worth of data into a single table about once a week. To achieve this, I'm creating an object (created from parsing XML), and sending the data within that object to a ...
1
vote
1answer
178 views
Another BCP Export [Fail]ure
All, in SELECT Data Set Using Stored Procedure with BCP Error @Remus Rusanu provided a great solution to the problem. However, this evolved in to another problem: this BCP query now runs
DECLARE ...
1
vote
3answers
436 views
SELECT Data Set Using Stored Procedure with BCP Error
All, I have a BCP export query. It is failing with the useless error mesage on BCP usage:
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f ...
7
votes
3answers
341 views
How do I write portable SQL that refers to a linked server?
I've got a stored procedure that refers to a linked server. In several places throughout the procedure I've got something like the following:
INSERT INTO [TableName]
(...Columns...)
SELECT ...
3
votes
1answer
321 views
Who changed/modified stored procedure in SSMS 2005 or 2008? [duplicate]
Possible Duplicate:
Determining how a schema change occurred?
I have a stored procedure that was modified late last night and just spent the majority of the morning tracing issues back to ...
1
vote
1answer
652 views
Production SQL Server High CPU for a Single Query
I have a single query which is consuming a larger amount of CPU than I would expect in SQL 2008. I am not able to determine why the CPU is spiking for this single query.
I can trigger an ...
2
votes
1answer
573 views
How to modify a stored procedure using SQLCMD for MS SQL?
Suppose a stored procedure as follows have been created using the Microsoft SQL Management Studio.
use testbase
go
create procedure testtable_pricesmaller
@pricelimit money
as
select * from ...
4
votes
2answers
2k views
"Could not find stored procedure' even though the stored procedure have been created in MS SQL Server Management Studio
I have created a table testtable inside the database testbase that have the following structure:
product_no (int, not null)
product_name (varchar(30), not null)
price (money, null)
expire_date (date, ...
6
votes
1answer
265 views
CATCH block is triggered when it should not
On my neverending quest for shooting myself in the foot with save transaction I seem to have found even more ways to fulfill the quest purpose. The save transaction clause itself this time is out of ...
5
votes
3answers
1k views
RETURN statement before DEALLOCATE CURSOR
Question about use of Cursors in combination with RETURN in a SQL Server 2008 Stored Procedure
Consider this example:
CREATE PROCEDURE [dbo].[test]
@ReturnEarly BIT = 0
AS
BEGIN
SET NOCOUNT ...
2
votes
1answer
120 views
Find out what setting were used for a given stored procedure
As a follow-up to my previous question:
is there a way to need to find out what the ANSI_NULLS and ANSI_PADDING etc. settings where when a given procedure was created in my database ?
It seems my ...
6
votes
2answers
343 views
SQL Server database : moving from 2008 to 2005 - encrypted procedure issue
I could normally use generate scripts / DTS to move data and tables etc. However one of the databases has a large amount of encrypted procedures that I can't script to move.
Neither do I have older ...
2
votes
2answers
464 views
Bulk grant execute permissions for scalar functions & stored procedures
We have a situation where we have restored a large number (50+) of MSSQL2008 databases from backup and most if not all of them require that a user is granted EXECUTE permissions on scalar functions ...
0
votes
1answer
133 views
Need a stored procedure to check and update row when it does not already exists.
Need a stored procedure that will check and then update the rows (with username & email) except the id (auto incremented with a unique one).
For example, if id = 5 has, the username abc and the ...
5
votes
3answers
668 views
Passing in the table into a stored procedure
Is it possible to pass in the name of a table into a stored procedure?
For example, suppose you have several views of the same table. They all have the exact same structure.
You want a store ...
1
vote
1answer
265 views
Merge multiple table output but indicate which tables the records came from
I have an application with a function that uses a stored procedure (SQL Server 2008 R2) to pull in and arrange data from one table. Now, I’ve been asked to make it pull from two tables, but it’s not ...
2
votes
1answer
132 views
Stored Procedure doesn't show result in SQL Server
I have created a stored procedure (to be used in SSRS) that has parameters whose values are more than one. When I execute this stored procedure in SSMS by providing the values for that parameter, SP ...
4
votes
1answer
330 views
In a CASE Statement, which is faster: “WHEN [field] in (0)” or “WHEN [field] = 0”?
I'm looking at a stored proc that another guy has written and every WHEN clause is using an IN statement instead of =. My gut tells me this isn't as fast, efficient, etc.
For example:
CASE WHEN ...
5
votes
2answers
8k views
Granting Execute Permissions on Stored Procedures, Functions and Views
I am using a user which has read permission only. It basically has permission to
Connect
Execute
However, it does not have execute permissions on Functions and Stored Procedures. In part of my ...
1
vote
1answer
580 views
Executing a stored procedure on remote database
I have 2 databases on the same server. DB-A and DB-B. DB-B has a user that has read and write access to database B. I would like to grant the user in DB-B execute permissions to 2 stored procedures in ...
5
votes
2answers
795 views
How can I detect broken stored procedures after a schema change?
I've modified a central table in my database, and sp_depends literally returns hundreds of results, and I'm concerned some of those stored-procedures might not compile anymore after my change.
...
3
votes
1answer
317 views
How to change database owner for login and database created inside stored procedure?
I have a signed stored procedure that creates a new database, a new login and assigns the new user to be the owner of the new database. Well my SProc creates the new login and new database but will ...
1
vote
2answers
682 views
Should I put the error handler inside the loop, or the loop inside the error handler?
When a procedure is looping over a statement that could raise an error condition, should I put the loop inside the error handler, or put the error handler inside the loop? I want the procedure to run ...
2
votes
1answer
3k views
Table-Valued Parameter as Output parameter for stored procedure
Is it possibile to Table-Valued parameter be used as output param for stored procedure ?
Here is, what I want to do in code
/*First I create MY type */
CREATE TYPE typ_test AS TABLE
(
id int ...
1
vote
1answer
60 views
SQL Server many active create procedure processes
While troubleshooting performance issues on a SQL 2008 instance, I've noticed there are several SPIDs which appear to be executingcreate procedurestatements for already existing procedures.
Is this ...
3
votes
2answers
1k views
SQL Server 2008 T-SQL select hanging, but not dead locked
This is a pretty strange issue so bear with me. I have a stored proc that does some heavy duty processing. When it runs well it usually takes a few minutes depending on server load, but occasionally ...
1
vote
2answers
102 views
SQL Server RandomNumbers Stored Procedure Error
I tried to create a stored procedure for generating random numbers but it doesn't work; the random numbers are identical in every record.
CREATE PROCEDURE Update_Driver_Position
@TempName ...
3
votes
3answers
2k views
Stored procedure executes too long
We use SQL Server 2008. When I am watching in SQL Server Profiler I found some queries that take for example 20 seconds. The same query (in a stored procedure) when executed in SQL Server Management ...
1
vote
2answers
1k views
Print database_size from sp_spaceused
Using SQL Server 2008, I have found that the database size can be obtained using
exec sp_spaceused
This procedure returns two tables:
database_name | database_size | unallocated space
reserved | ...
3
votes
2answers
1k views
How to optimize this dynamic stored procedure
I have a stored procedure which is retrieving data using 20 tables.
Sample of the procedure:
CREATE PROCEDURE GetEnquiries
(
@EnquiryDate DATETIME = NULL
)
AS
...
4
votes
1answer
160 views
How can I know which store procedure or trigger is using a table on SQL Server 2008 R2?
This is the case that in the DB I'm checking, there is an archive table which keeps the user history, and there is a trigger or store procedure that after some time delete rows from this table, in ...
2
votes
3answers
2k views
SQL Server: How to call stored procedure without schema name?
SQL Server 2005std/2008web edition
db=user=schema=owner='John'
I'm moving website from one server to another. This piece of code works well on old server with SQL Server 2005.
Dim sqlCmdVehicle ...
0
votes
0answers
111 views
how do i bulk copy a huge amount of data and keep the same table updated through stored procedure in SQL SERVER [duplicate]
Possible Duplicate:
How to move data from big table
In my project i need to fetch datas from different tables in a data base and create a new table with the same colmn names for all those ...
0
votes
1answer
296 views
How to start and then stop one cyclic process
I have to start cyclic process in a stored procedure and then have to stop it after some time (after 12-24 hours). Stored procedure's work should not be started twice. SQL Server client (caller) ...
9
votes
1answer
1k views
How do you ORDER BY a parameter?
Just wondering if I could solicit some feedback on a stored procedure I'm running and whether there's a more efficient way of handling the scenario (I'm pretty sure there will be!).
Basically I have ...
4
votes
1answer
854 views
Can I call SMO from pure T-SQL?
I know how to script a stored procedure using PowerShell and SMO:
[System.reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null
...
1
vote
2answers
1k views
SSMS: Show execution plan for a stored procedure as a single tree
I execute a stored procedure with an option "Include Actual Execution Plan". The execution plan always is represented by multiple statements each of which has its own execution plan.
MSDN states the ...



