Questions tagged [sql-server]

Microsoft's SQL Server is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases. It originated from the Sybase SQL Server codebase, which is why both products use the extension of SQL called Transact-SQL (T-SQL).

Filter by
Sorted by
Tagged with
3
votes
2answers
2k views

Subquery v/s inner join in sql server

I have following queries First one using inner join ...
4
votes
1answer
270 views

Backup a database over an SQL connection

Developing some industrial WinForms application for some industrial setting, I wanted to provide users of our software with a convenient way to back up the database the software uses (to send it to ...
2
votes
2answers
163 views

Throwing a custom error in a stored procedure

I'm wanting to throw an error when reference keys are missing, however instead of failing through a integrity check, I want to list out the missing keys. I've created the below which works. However I'...
5
votes
2answers
230 views

SQL Query Tuning

I have a mammoth SQL statement, however it's taking a long time to load (27 secs on the server). I think the issue lies with the IN statements towards the bottom (the IN statement is repeated too, can ...
1
vote
3answers
1k views

Using a Dedicated Class & Constructor to initialize Stored Procedure for SQL Transaction

I will try to be as concise as I can: The goal: trying to universalize a specific section of a project, that is dealing with the SQL database transactions. To assist you with your answer, I've ...
1
vote
1answer
3k views

Is this a good way to limit the occurrence of OutOfMemoryException?

I have a class that uses the SqlBulkCopy to bulk insert data into a SQL Server database. My original implementation just passed the m_buffer (which is a reference ...
3
votes
1answer
3k views

Review Insert/Update stored procedure

I am not a DBA nor do I play one on TV. My application is retrieving information from Facebook and storing it into our own database. I want to retrieve the Location Post information of ...
1
vote
1answer
1k views

How to dump UCCX stored procedure results via c# to SQL Server

I am writing a simple-ish c# CLI app to improve our telephony reporting system. At present, I have a nightly DTS package which dumps a couple of tables from the Cisco telephony box into a database ...
3
votes
1answer
237 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 ...
7
votes
1answer
139 views

Auditing a complex mix of reasonably small tables

I plan to use the following approach to audit the tables that represent user-editable configuration of an automated system (over the course of system's life these will be inevitably extended in their ...
3
votes
1answer
112 views

SQL view, better way?

I there a better way to write this query? I feel sure it can be done in one statement with joins, but I couldn't get it, and I'm afraid I've made it too slow. What suggestions do you have? I'm ...
4
votes
3answers
8k views

SQL Server Split function

I know there are some answers about a user function to split chars and I have one already running (found one years ago in the net and modified it to my own needs). Since I use this function very ...
7
votes
1answer
8k views

Splitting an address into fields in SQL

I have the following code to split an address string in T-SQL. Excepting the unit number, which is already in its own field, it would affect too much of the application to split the address into ...
3
votes
2answers
303 views

Any way to speed up this UPDATE?

SQL: ...
3
votes
3answers
14k views

Search using stored procedure

I want to search a DB table and display the records in a gridview below is my stored proc ...
1
vote
1answer
48 views

SQL iteration-Insertion plus renaming

Base Info Two tables: tData, tData2 Exactly the same columns About 200,000 records SQL Server 2008 R2 Logic At first sight we need to insert tData rows into tData2. What else? We need a renamed ...
2
votes
1answer
429 views

Generic PHP function for making a struct out of multiple resultsets from a stored procedure call

The stored procedures must return their first resultset in the form: ( [index] int, [id] varchar(50) ) where [index]...
2
votes
2answers
4k views

PHP Login/User Creation Validation Function

I'm VERY new to PHP and have begun writing a basic login for a website that uses data from a Microsoft SQL server to display information on the web. Below are 3 snippets of code (two functions from ...
2
votes
2answers
2k views

Which SQL statement is faster

My co-worker claims that using a parameterized Like statement is equivalent to dynamic sql and won't have its execution plan cached for reuse. He says that using ...
7
votes
1answer
899 views

Listing teams by total distance and bonus

I had to write a SQL query recently to do a few joins and sums, and at the end of it I realized that I have nearly written a storybook. I know the tools to optimize it, but my trouble is the length of ...
1
vote
2answers
440 views

Is there a way to refactor this Cursor?

So I got this query from another analyst here and I'm a little stumped as to why a cursor was used instead of just joins. Could I please have some help trying to refactor it? I am using MSSQL 2008. <...
14
votes
1answer
9k 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 ...
1
vote
2answers
340 views

Users' timetable database

I wish to create a database for a webpage where users are able to add their own events to a timetable. Users will be able to decide if the events should be recurring (weekly) or not. Users should be ...
2
votes
1answer
144 views

List of students with their classname in current year

I have 3 tables: students and classes and years. In a fourth table called ...
2
votes
1answer
145 views

Statistics updating SQL Query

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 ...
4
votes
1answer
193 views

Returning the title of a record

I want to return the title of a record if one exists or the word 'invalid' if not: ...
2
votes
1answer
13k views

Query to get number of related records in 2 child tables

I have a category table (brands) and 2 other tables (Pens and Pencils) that have parent-child relation with this table through a ...
3
votes
1answer
188 views

Oracle to MSSQL data migration is slow on INSERT

I wrote a method that gathers data from an Oracle server, formats and encrypts the data then inserts it into a MS SQL server. The method moves about 60000 records and takes a bit long and is a little ...
5
votes
1answer
106 views

Adding a new record to the beginning of the approval chain from the delegation chain

Table Structure ApprovalOrder int EntityCode varchar CostCentre varchar DelegationCode varchar ProjectCode varchar RoleGroup varchar Position varchar ...
3
votes
4answers
2k views

Shifting records in SQL Database while sorting with 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, ...
0
votes
2answers
207 views

Query to compare execution performance metrics for the three most recent months

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 re-...
5
votes
1answer
268 views

SQL - How's my formatting?

I'm somewhat new to SQL (using it in the past but only being exposed to it heavily in my current role). Unfortunately nobody at my current company has really given me any advice on formatting. How can ...
2
votes
3answers
112 views

Query for combining results of same query running across multiple databases

I wrote a query to run the same query across multiple databases and combine the results. While it seems plenty quick I was wondering if there is a better way to do this. ...
3
votes
2answers
3k views

Relationship design for auto parts store database

I'm creating a design database for an autoparts store (this is a project school). For the moment, I'm not sure if the relationship model especially in MODEL, ...
10
votes
1answer
1k views

SQL Server stored procedure boilerplate

What would you do to improve upon this boilerplate empty stored procedure, being mindful of the delicate balance between length, complexity, performance and clarity? ...
2
votes
3answers
30k views

Inner join with first result

In SQL Server, there is two tables: Houses, and their images. I need a list with 20 houses with the first of their images (only one). I tried: ...
2
votes
3answers
12k views

Database connection class performance

This is my general database connection class. I am using this class to execute my queries through website. What would your suggestions on how to improve performance be? (Running MSSQL 2008 R2 SP1 - ...
11
votes
5answers
4k views

T-SQL statement to breakdown UserAgent information

I have a table that contains the UserAgent string and a Count of how many times its seen. The T-SQL below is used to give a ...
3
votes
2answers
15k views

Splitting a string in an SQL query

BudgetCode is in the format 'xxxx-yyyyy-zzzzz'. This splits it correctly but I think that there has to be a more efficient way. ...
2
votes
1answer
221 views

Recommendations for stored procedure

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 ...
0
votes
2answers
1k views

Optimize slow SQL query

There is a application with a very slow query (listed below), and I have to optimize to run faster. The truth is that I don't know where to start. Any help? Thanks! ...
2
votes
4answers
398 views

Reduce the code in a WHERE clause without using dynamic SQL

How can I write the following T-SQL query part in a shorter way without using dynamic SQL? ...
4
votes
2answers
207 views

Inner cursor performance issues [closed]

Before I tried to avoid using cursor because of performance issues. But now I have to do some calculations to reach some goals. I have a stored procedure that has a code like this: ...
5
votes
3answers
786 views

Get distinct of two columns

I want to get distinct of two columns from an SQL table. Can I optimize this query? ...
7
votes
5answers
5k views

Database schema for a school

Here is the database query needed to create the database: ...
4
votes
2answers
365 views

SQL paged search results

I'm trying to figure out a way to simplify implementing paged searching in sql server. My restrictions are: has to be in a proc. can't use dynamic sql. Here's my sample query: ...
7
votes
1answer
504 views

Tame this Beast: TSQL Unpivot

Okay... here's the beast: ...
7
votes
3answers
199 views

Return Data and Update Row without Multiple Lookups?

I have a stored procedure that looks up an article based on the article's title. But I also need to increment a column in the same table that counts the number of times the article has been viewed. ...