All Questions
Tagged with stored-procedures t-sql
3,585 questions
0
votes
1
answer
142
views
Use a stored procedure in a SQL query
I need to use some data that comes from a stored procedure and I want to put that data into a select statement. I would use a function but I am not allowed to and whoever set up this database decided ...
0
votes
1
answer
100
views
Generate random characters in stored procedure
I'm trying to create a stored procedure to randomly generate two unique alphanumeric characters from the following character set on SQL Server 2016: ABCDEFGHIJKLMNPQRSTUVWXYZ0123456789 (35-character ...
1
vote
2
answers
109
views
What causes @summary variable to fail in SQL Server stored procedure?
I have about 15 existing stored procedures that I modified to add logging. All of them are working except this one.
When Visual Studio attempts to execute the query, it displays the following error:
...
0
votes
0
answers
68
views
Stored procedure that needs to get another tables data output to return
I am trying to figure out how to do this query using T-SQL that will allow me to query the table it finds the data in. Currently I have this in a stored procedure and @Temp is the temp table it puts ...
0
votes
3
answers
94
views
Protect stored procedure from schema changes
I want to protect a SQL Server stored procedure from changes to the underlying tables.
As you can see in the test below, I am able to break this stored procedure with no warning or errors.
Ideally I ...
-1
votes
1
answer
60
views
Cleaning up Cursors without Spaghetti and Duplicate Code?
I am using GoTo for Closing and Deallocating the Cursor. Is there a better way to write my code? Note, this code is for learning how to use Cursors and output Parameters.
I am new to TSQL, so feel ...
-1
votes
1
answer
56
views
Only shows NULL when using the variable which set with Scope_Identity() on JOIN statements in a stored procedure
After INSERT and setting a variable (@scopeID) with SCOPE_IDENTITY(), when I try to JOIN tables with @scopeID, I can only see the value of @scopeID, and other variables are NULL.
INSERT INTO ...
0
votes
1
answer
105
views
Pagination of distinct records from the stored procedure using offset
I have two tables and columns as below
Product : Id, Name
Order : Id, ProductId, Name, CreatedDate
Now I want to do pagination of unique Product Id records.
Select P.Id As ProductId, P.Name As ...
2
votes
1
answer
82
views
Stored procedures common sense pattern for dynamic query situation [closed]
I'm designing a table which could hold hundreds of thousands rows, as an example:
CREATE TABLE [dbo].[Messages](
[MessageID] [uniqueidentifier] NOT NULL,
[Number] [int] NOT NULL,
[...
-1
votes
1
answer
240
views
Stored procedure creation error in SQL Server 2022
I attached a database to SQL Server 2022 version and added a new table URLabelHeader. While adding a new stored procedure I am getting the following error.
CREATE PROCEDURE [dbo].[spSaveURLprocess]
...
1
vote
1
answer
82
views
id obtained through output in an insert query needs to be passed to another insertquery
Until this line
EXEC sp_executesql @InsertQuery, N'@product_id BIGINT OUTPUT', @product_id OUTPUT
I managed to obtain the product_id correctly, the problem is when inserting in the @InsertQuery2, it ...
0
votes
1
answer
91
views
How to convert a query and not call the subquery several times?
I have this query:
SELECT
t.[DataTran]
,t.[Dok]
,t.[Product]
,p.idxbox
,po.[Mark]
,po.[Model]
,(SELECT
TOP(1) [poz_La]
FROM [...
0
votes
0
answers
175
views
WITH EXECUTE AS OWNER gives error to server admin
In my vba application my users can change their roles in SQL server database by invoking the following Stored Procedure:
ALTER PROCEDURE [dbo].[usp_chgRole]
@usr nvarchar(7), @db nvarchar(8), @...
0
votes
1
answer
138
views
Records in input to stored procedure
I would like to know if someone can help me sending multiple record to a SQL Server stored procedure.
The scenario is that I have a trigger with a complex logic inside and I would like to move some ...
0
votes
1
answer
830
views
Can't use User-Defined Table Type as a parameter in procedure
I am working on a database in SQL Server and want to create a procedure similar to this:
create procedure db.insert_data
@variable db.user_defined_type readonly
as
begin
-- code
end;
This ...