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).

learn more… | top users | synonyms (1)

0
votes
0answers
13 views

Create variable and use in one stored procedure

Aim: Find a value via a stored procedure then run a second process in the same stored procedure than than calling a second stored procedure. Query: When a call is 'simple' i.e. not Where x y then... ...
0
votes
1answer
21 views

Creating a wrapper for SqlClient

I'm trying to find out what is the best way to create a class so I can use it to connect to the SQL Server and be able to rollback everything if a single error exists. Right now, I'm using a single ...
1
vote
1answer
44 views

Stored procedure where column to ORDER BY depends on input parameters

I'm getting three inputs and based on those three inputs, I'm returning. Input items may vary, so I used CASE WHEN statements here. Is this code correct? If so, ...
3
votes
2answers
42 views

Updating user log in time while he logs in to the web page

My intention is to store the user's last login date and time when he logs in to the web page. I pass his username and password to the stored procedure to check whether is it correct or not! I believe ...
4
votes
1answer
31 views

Checking that data has been created in multiple tables

I have 4 tables that I want to check for data. When there are Rows in all the tables, I want to print a message for success. When there aren't any rows in any table I print an error (when 1 or more ...
4
votes
1answer
78 views

Classes for reading data from Sql Server into objects

The following is a set of classes that read metadata from Sql Server tables and populates local objects. It works, but I feel like there's too much duplication happening and too many places changes ...
8
votes
1answer
54 views

Assigning permissions to new role without RBAR

I'm currently faced with a problem in our SQL Server environments. We need to migrate our existing logins, users and roles to a new login, user and role with the same permissions as the old. I've been ...
6
votes
1answer
43 views

SearchSchoolData - what class where?

I am running a test load using Telerik Test Studio using 100 users at once entering search filters on a page that calls a stored procedure. My application that calls the stored procedure is an asp.net ...
3
votes
2answers
33 views

SQL server efficiency, comparing date time of latest record and the one under it

I have a snippet of SQL that compares the last two records and gives the datediff in seconds. However, the way I have it is quite slow, taking up to 20 seconds to execute depending on how many ...
-4
votes
3answers
107 views

Application search form

I have a search form in my application. When I search, it takes too much time to retrieve and display data, so I need to optimize this code. ...
1
vote
2answers
163 views

Multi-Table Unions [closed]

I've been using joins for years but in this instance I want to be able to do different queries on different tables which may have different structures due to clients. Long term we are aiming to make ...
2
votes
2answers
85 views

SQL Server to MongoDB Template

Looking for feedback on a set of templates I've just created. I'm planning on converting them to Yeoman but want to make sure they're ready for prime time before doing so. They are currently in ...
4
votes
1answer
54 views

Luhn algorithm MS-SQL

This a solution Luhn algorithm for credit validation. This algorithm is a basic one inspired by wikipedia. I mean no check for length, type, and so on. You can enhance the base code as you want it to ...
5
votes
3answers
137 views

SQL database design for ecommerce

I need to create a database which stores details products, Manufactures,Suppliers. So initially I divided Products into categories and subcategories. These are the tables I created. ...
7
votes
1answer
40 views

Stack Exchange Data Explorer query to find upvoted questions with only downvoted answers

I have written a SQL query against the Stack Exchange Data Explorer that identifies answered questions with a positive score for which all the answers have a negative score (this was an answer to this ...
3
votes
1answer
30 views

Return most recent non null field values for multiple unknown fields

I am attempting to create a stored procedure that looks at one table and imports changes in that table to another. This stored procedure is going to be preformed on multiple source tables and will ...
6
votes
1answer
105 views

Generate random records for table in SQL

I'm doing a project in ms sql and I have to fill table with random records. Here is a definition of table: ...
5
votes
1answer
44 views

Finding bad Narutos

While looking for Naruto posts (= overlooked accepted answers well worthy of upvotes), I noticed some odd false positives, selfie answers, where the user who asked the question accepted his own answer ...
7
votes
1answer
96 views

Finding answers where happy customers commented “thanks”

To find answers where users expressed their gratitude (by mentioning "thank" in comments), I put together this SEDE query (latest): ...
0
votes
1answer
70 views

EF Code First Seed Method for States/Countries Part I

I am working to complete this even further, but here's what I've got thus far... (See my other post for the definition.) ...
5
votes
1answer
140 views

Genetically engineered doodle creatures selector combo

I have created an awesome cheat/fan page for the game Doodle Creatures with the help of some cool people in The 2nd Monitor. Is there anything I can do to improve this code? Here is my ASP.NET ...
2
votes
2answers
47 views

Replace CASE WHEN statement with something more sensible

While checking my SPs today I found that I have, ...
10
votes
2answers
91 views

Forgotten zombie killers

Zombies are questions with no upvoted answers. I came up with this SEDE query to find answers with zero votes on questions that have no accepted answer and no answers with greater than zero score. In ...
16
votes
2answers
130 views

Naruto, where are you?

During Winter Bash 2014, the Naruto hat was awarded to users who gave an answer that got accepted but hasn't received votes for 12 hours. It was a weird thing, really: why would someone ever accept a ...
2
votes
2answers
80 views

Haversine formula in SQL

This is an implementation of the Haversine formula in Microsoft Transact SQL. How can I simplify the function? ...
4
votes
1answer
44 views

Selecting internationalization preferences

I have a query below using CTE. I am wondering if there are some approach other than this. So I am collecting some advise to refactor it. Or does the query look good even though I am using this ...
2
votes
2answers
204 views

Timeouts when calculating stock ratings using LINQ

I'm getting a lot of timeouts with the following code and I'm running this method around 10,000 times so I need to figure out how I can optimize this so the timeouts will stop. I am getting timeout ...
1
vote
1answer
20 views

Inserting into Group_roles table for all rows in Group table

I have five groups in Group table as Group1, Group2, ...
3
votes
1answer
63 views

Is the usage of SQL Cursor appropriate here?

I'm looking for following kind of feedback: Firstly, is the use of a cursor an overkill here? Is there a simpler way to do what I'm doing in SQL? Could the script go terribly wrong? I have limited ...
7
votes
2answers
140 views

What are my highest activity streaks?

I have written the following query to figure out activity streaks on a per-user basis. I find it... Ugly... And would love to improve it! Limitations Those are explained as commented text at the ...
17
votes
6answers
633 views

Winterbash 2014 “Red Shirt” Estimation

Some fellow code reviewers (hi @Janos!) have been inquiring about a SEDE query to allow to check progress of the Red Shirt "hat" progression. Try it here! Background Red Shirt cast 5 ...
10
votes
6answers
8k views

Select first value if exists, otherwise select default value

Given an instance of SQL Server, imagine there's a table named Configuration, which has three columns: ID, ...
7
votes
1answer
70 views

Fascinating, ma'am

Finding a famous question with high score I haven't voted on yet was proving to be a bit difficult for me. So I came up with this simple SEDE query to find good candidates: ...
13
votes
2answers
81 views

Bling Accounting - Badge summaries

A question was raised in chat (hi @malachi) about how you can count the number of badges of a given metal (bronze, silver, gold). This can be hard to do because the medal details are not stored in the ...
8
votes
2answers
176 views

Checking for Duplicates, Except

I have a query that returns records that have duplicate names within a given DBSTATUS. I used to do this with a direct connection to the remote oracle database ...
11
votes
3answers
148 views

Tag badges per user SEDE query

I wanted to see where I lined up with other users on tag badges (I wanted to count just bronze but figured I would start with all of them to start out with). Here is the query that I ended up with: ...
12
votes
2answers
84 views

Archaeologist Progression

One of the badges available on Stack Exchange is the Archaeologist badge. This is awarded for making 100 edits on posts that had been inactive (at the time of the edit) for 6 months. There is no ...
5
votes
3answers
97 views

Selecting Employee details from a complicated schema

I have a "litte" problem with my stored procedure because I need some values selected at a point in time. I need to do many select and group by's in my Left outer join which looks and feels like I am ...
3
votes
1answer
64 views

SQL stored procedure for fruit checks with several joins

I developed a SQL stored procedure which works lovely, but when under stress, it takes more than 2 minute to get back to the user. I am providing the stored procedure but would also provide the table ...
3
votes
2answers
112 views

SQL cursors and dynamic SQL

The idea is to have a heading for each date returned by the query. This could be any number of dates. I dynamically altered the #table which is ugly but there is no other way. Ultimately I would ...
12
votes
3answers
269 views

Creating an object oriented model in VBA using COM and ADODB from 2 depended SQL tables

The story... A bit of background info and how is the database designed... Please notice you don't really have to rebuild the tables in SQL but I shared an SQL Fiddle just in case and screenshots1 of ...
3
votes
2answers
57 views

Running validation procedures on a table

I am working on a project that has to parse through a text file and perform validations on certain fields in the file. Some of the validations are basic(i.e. data types), and other's are a little more ...
2
votes
2answers
39 views

Cluster date time values

I came up with this TSQL for SQL Server 2008: ...
3
votes
1answer
1k views

File Exists Script Task for SQL Server SSIS

I have an SSIS package for SQL Server 2008. In this package, I need to verify that a file exists that matches a pattern of SomeFileName_*.txt where the wild card ...
3
votes
1answer
81 views

Better way to divide by the total count SQL

I have this query where I am working out the percentage of peoples occupation, I have a sub query that works out the total count of people codes and that result is what I used to divide by, I could ...
11
votes
4answers
627 views

LW, MTD, STD, YTD Sales… all in line and looking pretty

That's Last Week, Month-to-Date, Season-to-Date, and Year-to-Date sales. I have a table-valued function for each one, that takes a date and returns all ...
11
votes
2answers
331 views

SQL-Server Merge Statement with .NET DataTable

Background: I'm trying to synchronize order information between Oracle and SQL-Server databases and allow users to be able to track any changes between what has been replicated via an ASP.NET web ...
2
votes
2answers
56 views

Assign Specific Value If BitField Is True

My colleague created this SQL to handle certain user selections which are based on an on/off bit flag. The goal is to identify those individual bit flags with a specific integer which will be used in ...
3
votes
2answers
45 views

Extract last record inserted for each key identifier

I have a table with this schema ID, int primary key PathKey, string not null InsertDate, datetime not null Value, int not null In the table there are a ...
3
votes
2answers
75 views

Finding the runtime of a task by name

Can this query be improved? I iterate over a couple of thousand times, and if I can improve it, it should decrease the run time. Otherwise I might look into using a batch instead of doing one at a ...