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)

5
votes
1answer
36 views

Searching posts/comments by keywords

I've put together another simple query that allows you to search post/comments with specific keywords. At the moment, only post bodies are checked. ...
0
votes
2answers
38 views

Creating multiple objects from SQL server extract

I've created a simplified prototype solution as a sort of proof of concept before starting a larger program. Here is the test data used to build the objects: ...
0
votes
0answers
17 views

Merge inserted and deleted tables in SQL trigger

I have a table with a Balance column of type decimal(18,0). I want to get updates to its ...
1
vote
2answers
45 views

Custom SQL statement

I am just wondering if my code can still be simplified. I intend to make it reusable in all update statements. ...
8
votes
3answers
379 views

Popular questions by view count

I made this query to create a graph of a user's popular questions and the view count on that question. It allows for a minimum of 500 views, and a score of ...
3
votes
2answers
32 views

Percentage of questions that are unanswered or answered - Part 2

I've refactored my previous query and added better checks when selecting the data. The query link can be found here. The formulas used to calculate the two percentages are the same, and can be seen ...
2
votes
0answers
13 views

Trigger that updates counter

I've got the following schema, which can not be modified since it's a problem taken from an exam: ...
2
votes
2answers
47 views

Job execution on records supplied by database

I have a requirement to check all records in a table which is big (Around 1.5-2 million records). What I am doing is very simple, just get all the records and loop through one by one, and do things. I ...
10
votes
2answers
287 views

Percentage of questions that are unanswered or answered

I put together this simple query which calculates the total percentage of answered questions and unanswered questions. The formulas used to calculate these are shown below: $$ \text{Answered ...
1
vote
0answers
29 views

Get Next and Previous “Load Day”

I keep looking at this trying to figure if there's a better way. All three functions work, but I wanted to get some insights and ideas from others. IsLoadDay ...
2
votes
1answer
35 views

SQL Nested Selects

I was wondering if there is a better way to do the nested selects so that the firstname and surname is only doing one select ...
1
vote
1answer
29 views

Pull data from database to generate XML files

I have the following script in Perl that does the following: Prompts user for time in epoch. If user enters '########', the query will look for all reports generated after that date/time. If user ...
5
votes
2answers
94 views

SQL procedure with cursor to check if values in table 1 are also in table 2

The problem is that I'm checking if result from cursor exists in CDN.ZamNag table for every iteration. Is there any better way to check if values in table 1 are ...
0
votes
1answer
31 views

Synchronizing two SQL Server database tables with the most recent changes to both tables

I'm very new to SQL, but I'm coding a C# program that interacts with a database. There's a master database on my computer, and there's a client database on my tablet. When I re-connect my tablet to ...
5
votes
2answers
127 views

Finding questions to answer - Part 2

I've refactored my previous question finder, and added multi-tag support, and support for searching for keywords in the question titles. Essentially, what it does is find questions that could be ...
2
votes
1answer
42 views

Backing up two tables using SQL transactions

I'm using a transaction statement in SQL Server 2012 for the first time. I want to insert Table1's data in Table1_Backup before ...
8
votes
1answer
39 views

The opposite of CodeLess Questions query

What's the opposite of CodeLess Questions? Perhaps CodeOnly Answers? (Also known as code dumps.) Inspired by the opposite question, here's the opposite query: ...
0
votes
1answer
49 views

Using Stored Procedures in ColdFusion / Lucee

This is how I write all my database interactions now in Lucee: ...
11
votes
1answer
273 views

CodeLess Questions query

As part of an exercise by Jamal to clean up old questions on Code Review that have no code in them, I helped by writing this query on Stack Exchange Data Explorer: CodeLess Questions ...
4
votes
2answers
257 views

Database Update class using SQLCommand

I would like to have advice on this use of base class and derived class. This all works but is it a good way to achieve a SOLID class? ...
3
votes
2answers
203 views

Creating Sequential IDs

I'm using SQL Server 2014 with Visual Studio 2013. When I add a new record, identity column (seed 1, increment 1) "ID" increases by 1, and record added to the database. My table consist of two rows: ...
3
votes
0answers
84 views

Generic SQL Connector classes

The need came up the other day to be able to easily switch back and forth between making IBM DB2 queries and MS SQL queries. I didn't want to mess with NHibernate ...
0
votes
0answers
17 views

Create variable and use in one stored procedure

This finds a value via a stored procedure then runs a second process in the same stored procedure rather than calling a second stored procedure. When a call is 'simple' i.e. not Where x y then... I ...
1
vote
0answers
31 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
51 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
43 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
36 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
139 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
35 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
128 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
169 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
92 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
68 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
217 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
46 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
170 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
97 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
92 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
157 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
53 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
138 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
103 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
222 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, ...