Tagged Questions
0
votes
0answers
23 views
Difference Between SP with BEGIN/END and without BEGIN/END [migrated]
I have found some SP(stored procedure) written as,
CREATE PROCEDURE [dbo].[XXX]
(
-- Parameters
)
BEGIN
--- Actual Work
END
and some as
CREATE PROCEDURE [dbo].[XXX]
(
-- Parameters
)
--- ...
2
votes
1answer
35 views
SQL Server 'Execute As'/Revert pattern in a 'Try/Catch' Block
I wish to ensure I am using the "best" pattern when using an Execute As/Revert from within a Try/Catch block on SQL Server 2012. The below code "seems" to behave correctly... Am I missing anything or ...
2
votes
1answer
80 views
How can I improve the following stored procedure?
I have created the following stored procedure which duplicates a record in a table and also all its related records in other tables however since I am a newbie to SQL I would appreciate it if someone ...
-1
votes
1answer
61 views
Using xp_cmdshell
Am I doing it fine?? Its only for setup not executed repeatedly
CREATE TABLE #temp
(
id INT IDENTITY(1, 1),
name_file VARCHAR(500),
depth_tree ...
0
votes
1answer
47 views
Daily, Weekly, Monthly Individual Tech time in task Repoert
I'm trying to create daily, monthly and weekly SQL Query report to our services time we spent int task and total billing time just want to see if I'm on right track
GO
--Daily
SELECT ...
1
vote
1answer
79 views
Sql query to obtain totals and subtotals
I'm interested in knowing if there's a better/cleaner/more efficient way, to obtain totals and subtotals within a query, than my solution below.
The query works fine but I'm just intrigued to know if ...
3
votes
1answer
84 views
Is it necessary to replace this cursor in SQL Server 2005?
The Problem
I have a cursor that I am trying to replace (perhaps unnecessarily) in an attempt to clean up a stored procedure. Essentially what it is doing is counting each note for each member in a ...
0
votes
1answer
634 views
Data Structure for Categories and SubCategories
I have this relationship:
Many Objects to One Category
One Category to Many SubCategories
I am looking for the best way to store this in my Relational Database? Here were some of the ways I was ...
3
votes
1answer
132 views
Getting rows from several tables where one table doesn't include the rows from the next tables
I have some entity that is spread across three tables.
I have to get in a single result the following values:
All the values that are in the first table but not on the second nor the third.
All ...
5
votes
1answer
843 views
Conditional Create: must be the only statement in the batch
I only want to create this SQL function if the dependent Assembly exists.
I can do it using dynamic SQL, but it seems messy and I lose syntax checking (in
management studio). This function's ...
2
votes
1answer
109 views
Refactor my simple SQL Statement
I have the following SQL statement that I think could be improved in areas (I believe there may be a way to use where over having, but I'm not sure how and I'm sure there's a way to reference the last ...
3
votes
1answer
101 views
output parameter and exists condition
I want to return title of a record if exists or the word 'invalid' if not.
@ID int ,
@Title nvarchar(50) output
...
if exists(select * from MyTable where ID=@ID)
select @Title = ...
2
votes
1answer
74 views
Critique my SQL
Table Structure
ApprovalOrder int
EntityCode varchar
CostCentre varchar
DelegationCode varchar
ProjectCode varchar
RoleGroup varchar
Position varchar
...
1
vote
3answers
218 views
How can I improve this sorting algorithm?
I have a table in a SQL Server database, which holds information of some images, and the relevant gallery of them. The columns are like:
ImageId, GalleryId, Order
I have a unique key on ...
1
vote
2answers
145 views
SQL - Refactoring - How can this be done better?
I've been working on a semi-awkward query in that it uses a very high number of functions given its relatively small size and scope. I was hoping to get some feedback on any ways I could format or ...