Structured Query Language is a language for interacting with relational databases. Read the tag wiki's guidelines for requesting SQL reviews: 1) Provide context, 2) Include the schema, 3) If asking about performance, include indexes and the output of EXPLAIN SELECT.

learn more… | top users | synonyms

2
votes
1answer
34 views

T-SQL Constant Time Comparison

Explanation is in the function. Please point out any egregious errors: ...
3
votes
0answers
36 views

Twitter clone in Golang

I have built a Twitter clone in Golang, using object orientation principles. I wish to know the design mistakes I have made. ...
2
votes
2answers
49 views

Should I be using a stored procedure for this function in my code behind?

We typically do our saves and deletes for our asp.net pages (SQL Server as back-end) in the code behind. I've seen some reference the idea of creating a stored procedure for this purpose. Is this the ...
6
votes
2answers
247 views

Audit table queries for various combinations of search criteria

I've created a search page on a rather large Audit table (populated by triggers on every database). There are 4 fields you can search by (and I put each textbox next to each other): User ID, Table ID, ...
1
vote
0answers
23 views

Copying csv to sql_table

I wrote code that takes csv and export it to sql table. It looks like this: ...
1
vote
0answers
8 views

T-SQL Totp (Rfc6238 SHA2_256) Implementation

Using my previous function as a base I've come up the following: ...
3
votes
1answer
31 views

Returning two dates based on input

I created a function that will return 2 dates that depend on an input parameter. When the parameter is: 1 - return start date of current week and end date of current week 2 - return start date of ...
-4
votes
0answers
19 views

SDF queries to split the table into sub table [closed]

I have some data in my SDF Server compact edition file and I was wondering if there is any Query where we can split one table based on id into sub tables. Example: ...
3
votes
2answers
56 views

IEnumerable extension method that ingests SqlCommand and returns query results

The following ingests a preexisting SqlCommand and returns the values. A couple caveats right now. 1 ) Type properties must be named identical to the SQL column ...
4
votes
2answers
38 views

Basic Bill of Materials schema

I've been working on Bill of Materials mini schema for a while. At first I had single Part table where I've referenced itself. I was told it would be better to have ...
4
votes
1answer
60 views

Purchase-ordering

This is the Save function on my PurchaseOrder model in my real world production system. This code needs to write the state of ...
1
vote
2answers
65 views

Multiple choice game

This is a multiple choice game. It has a web page where you enter a question, which can have multiple answers along with multiple options. Can anyone recommend any improvements for my code? ...
5
votes
0answers
80 views
+100

A Groovier way of inserting and updating database records

I've written a simple little Groovy class handling my database interactions. All it has to do is check if a row exists in a target table with primary key values which match those of an incoming map. ...
5
votes
1answer
25 views

SQL with SUBSTRING / CHARINDEX

I've got a VARCHAR variable of this kind: @string = "BLABLA10;GOGOGO30;RES777;ANOTHER;" (several keyword + number separated ...
-3
votes
0answers
19 views

MySQL - rewrite a heavy multiple child-nested queries query

I'm on a task to improve an app's DB query. This heaving-loading query takes roughly 3-5 minutes to complete which is unacceptable. The previous developers built this query and they didn't do this ...
2
votes
3answers
38 views

Manual sorting of database output

I have a small (few elements) list of primary keys, sorted by hand. It come from user input. For example $ids = [15, 75, 54, 13]; The SQL command is simple. ...
1
vote
1answer
36 views

SQL update scripts taking too much memory and doesn't free it up

I have this piece of code that executes update scripts on the database. I have 20 .sql files that contains about 400 update scripts. The overall size of the files is around 60MB. When I execute all ...
1
vote
1answer
27 views

Managing employee photos in a database

I'm looking for a better way to manage employee photos for employee records in our database, and a way to query for the employee photos while having them on disk I have used a ...
3
votes
0answers
33 views

T-SQL Pbdfk2 (Rfc2898 SHA2_256) Implementation

Using my previous function as a base I've come up the following: ...
1
vote
3answers
123 views

Checking user access to servers

I have pasted a method I wrote, which is too slow to my liking (easily takes 60+ seconds to execute). The method loops through 12 different servers, checks if userX has access to any of the databases ...
4
votes
0answers
66 views

T-SQL Hmac (Rfc2104 SHA2_256) Implementation

I'm trying to implement an Hmac in T-SQL using this question as an guide. Please critique this: ...
1
vote
1answer
46 views

Generate short database identifier names from an integer

I wrote the following to generate short database identifier names (e.g. parameters). This isn't a terribly practical requirement and could be fulfilled nearly as well by using base-26, but what seemed ...
2
votes
1answer
21 views

MSSQL query with join and where clause

I've the following tables ...
5
votes
1answer
53 views

Working Days DateDiff function

I have a calendar table with a record for every date I need to care about (i.e. 365 records per year), with various meta-information about each date, including the weekday, the fiscal calendar week, ...
1
vote
1answer
21 views

Find foreign key membership including owner in SQL Server

Was hoping someone could sanity-check this SQL statement. I need to find the owner (schema), table, and column on both sides of a foreign key: ...
5
votes
1answer
60 views

Use PreparedStatement to insert into H2 database

This question is related to my question on Stack Overflow earlier today. After getting suggestions on using the PreparedStatement from Java I changed my code a ...
1
vote
1answer
33 views

Acquiring the number of contracts for persons

This script shows the number of contracts for persons. Table Contract has more than 82008 records and Candidate has about 7978. ...
3
votes
1answer
32 views
7
votes
2answers
140 views

SQL code reuse with C#

I have some code that allows for SQL reuse for C#. I'm pretty happy with it, but the fact that I can't find anything similar on the web makes me think I'm going about it the wrong way. I have a GitHub ...
8
votes
0answers
45 views

Find & Delete Duplicate Records on All Tables in current MSSQL Database

The purpose of this code is to search the entire database for duplicate records and produce a script that a user could then run to delete all of the duplicates. The stored procedure takes the ...
17
votes
3answers
3k views

Oh my goodness: How many selfies have I taken?

The title is a joke on how some people take a lot of selfies pictures Recently, in The 2nd Monitor, there was a brief discussion on selfie answers, starting with this post. At one point, a user said ...
2
votes
2answers
41 views

SQL query to select most recent version

I have the following table definition: ...
2
votes
1answer
51 views

Rock, Paper, Scissors, Lizard and Spock - Relational Paradigm

I found a few question about the game and IMHO it's a relational problem and better addressed by set logic. Thus I created this solution in SQL to get away from ugly JavaScript, elegant java and ...
5
votes
0answers
20 views

Finding closest points without duplicates and given distance threshold

Given a bunch of latitudes and longitudes stored as Points, I would like to determine the points that are closest to each point given some maximum threshold in meters. This is my first stab at this: ...
1
vote
0answers
28 views

SQL Query Count Records and Pull Distinct

So I need a little help. It is currently working but I might have over complicated it. So maybe someone has a better idea. Now let me try and explain it. I am trying this query, and it currently ...
1
vote
0answers
24 views

Generating business summary stats in SQL dynamically, based on an inputted date

I have the following Oracle SQL query to generate some system-stats. I am interested in making it a more efficient and readable query. ...
1
vote
0answers
29 views

Archiving an SQL table of sessions and statistics

What my query is doing: I have two SQL tables and I want to copy datarows from the one table to the other table. I am doing this for statistics. The source table includes all current ...
5
votes
1answer
30 views

Volunteer Signup Report - follow-up

Here is the original question. I've incorporated a lot of the feedback and I'm ready for another round of feedback and suggestions. Here is the PHP file's output. It creates a volunteer signup report ...
1
vote
1answer
26 views

Selecting mail messages that meet one of four search criteria

This is the current very repetitive and long SQL I have. Unfortunately I'm not that good at SQL to group this and get rid of the repetition. ...
2
votes
0answers
17 views

Delivery date checker for e-commerce website

I’ve made an e-commerce website where administrators can specify the number of deliveries they can make on any one day. I’ve written a SQL statement that then finds all delivery dates, finds any ...
4
votes
0answers
139 views

Stored Procedure code shortening and optimization

This stored procedure takes user defined table type as parameter. It contains data imported from an Excel file. Values inside that type are the same as in ...
1
vote
2answers
72 views

Float.Parse issue

I have telerik radgrid that has an SQL backend. What this function is doing is conditionally formatting the cells with in the radgrid. It checks each column to see if the min and max values are within ...
1
vote
1answer
40 views

Query performance of this Select Where each Column is a Select

I would like to know how to improve the performance of the following query: ...
0
votes
0answers
32 views

Health insurance claims query involving joins to fetch one column

General feedback is welcome, but I am especially wondering if there is a way to make things more efficient where I am joining an entire large table to gain use of one column (like when I join tables ...
-1
votes
2answers
47 views

Checking whether a grade combination exists

Below function checks if a grade exists ...
-1
votes
1answer
123 views

Performance comparision of SQL queries versus LINQ in Visual Studio 2012

I am new to VS 2012 and need to use it with SQL Server. I need to get data from a table in SQL Server 2012 with 500 rows and 15 columns and process the data in it and update another table. All this ...
1
vote
1answer
35 views

Summarizing income and expense information by month

I made myself a simple budgeting application. Each transaction is stored in the transactions table: ...
1
vote
0answers
65 views

Updating datetime fields from UTC to local time zone

I have created an SQL query to update datetime fields from UTC to local time zone. Can someone review this? ...
2
votes
0answers
25 views

Annualized Turnover Report

What can be made better? How ugly is my code? If it's terrible, where can I improve? ...
8
votes
2answers
81 views

SQL to find table containing all specified columns

I have the below code to list all tables which have columns DataAreaId and CountryRegionId. This works, but requires me to ...