Skip to content

Tag: sql-server

TRY/CATCH block vs SQL checks

Shortly, I am wondering which of the following is the better practice: to encapsulate my code in TRY/CATCH block and display the error message to write own checks and display custom error messages As I have read the TRY/CATCH block is not handling all types of errors. In my situation this is not an issue. I a…

Insert Data Into Temp Table with Query

I have an existing query that outputs current data, and I would like to insert it into a Temp table, but am having some issues doing so. Would anybody have some insight on how to do this? Here is an example This seems to output my data currently the way that i need it to, but I would like to

JPA with HIBERNATE insert very slow

I am trying to insert some data to SQL Server 2008 R2 by using JAP and HIBERNATE. Everything “works” except for that it’s very slow. To insert 20000 rows, it takes about 45 seconds, while a C# script takes about less than 1 second. Any veteran in this domain can offer some helps? I would app…

Duplicate check using SELECT or rely on unique index?

Using SQL Server 2012. I want to insert unique strings into a table. I always want to return the row ID of the unique string. Now, this can be accomplished in two ways. Which solution is the best? This is the table in question: Solution 1: SELECT first to check if the string exists. If it does, return its ID.

Return All Months & Years Between Date Range – SQL

I’m a bit stumped how I might go about this. I have a very basic query, that currently returns sales for each product, by year and month. It is grouping by year/month, and summing up the quantity. This returns one row for each product/year/month combo where there was a sale. If there was no sale for a m…

sql-ex exercise 39 failed on second server error?

Exercise 39: Define the ships that “survived for future battles”; being damaged in one battle, they took part in another. Database Schema: http://www.sql-ex.ru/help/select13.php#db_3 My approach: sql-ex says Your query produced correct result set on main database, but it failed test on second, che…