Improving performance of wildcard date pattern searchs

I have a wildcard search that I need to improve performance: mycolumn like ‘%-%%-%’ There is a way to do that? (for exemple, with Full-Text Index?) Obs: I have to find dates in my text that follows the pattern, like 21-07-2016. EDIT I have a legacy database that I cannot change the structure. So, I […]

Query Subquery Results in SQL

I am relatively new to SQL and I may be over thinking it but given the following table.I want a list of all students that are enrolled in Chemistry but not Mathematics.So given the data I would have Student 1. Student_ID Subject 1 Chemistry 2 Mathematics 2 Chemistry 3 History Here’s what I tried SELECT […]

Joining two tables in SQL Server when one table has huge data and other has few data

If I want to join two tables (not inner join), Left table has huge data (millions of record), and right table has few records. What should I prefer (Left or Right Outer join) and why.

How can I optimize this Update join query in SQL Server 2014?

I am using an update join query to update some records. I am actually joining an indexed table to itself, and updating where a pattern is met. This query worked fine for about a million records, but with 14 million records it just doesn’t scale. The reason I am doing it this way is because […]

Get time between two times on night to morning

I have a table that stores schedules by initial hour to end hour, some structure like | SCHEDULE_NAME | START_HOUR | END_HOUR | | ————- | ————- | ——— | | Morning Shift | 8:00 | 10:00 | | Evening Shift | 13:00 | 17:00 | | Night Shit | 22:00 | 2:00 | So […]

How to update a value in local SQL Server database

In my program I want the user to have the option to change the value (price in my example) in a local database, that I created. I’m having a problem with it. The connection works fine and it debugs well and even shows the message that “saving ok”, but it doesn’t change at all in […]

SQL Query: each column value is an aggergation based on a different filter on a temporary table

I want to get the count of rows from a table based on a specific criteria for each column in my result table. The table itself is a temporary table. The query below is what I want to accomplish but I don’t know what is the syntax to get to it: WITH table1 as( a […]

MS SQL Server (Ver 2008 or above) – How to recreate auto-incremental based in my ID column

I have a table in csv file (with an ID as numeric). I manually uploaded the information from the file to a SQL Server data table (creating my ID column as numeric). But, I want to recreate my ID column as autonumeric ID column that continue the number with the latest entry. Example: the table […]

SQL Server : convert string to numeric – Conversion failed when converting date and/or time from character string

I got a dataset in SQL Server Management Studio. The data looks like the following month Year ————- Feb 2016 Jan 2015 I want to create a numeric date using 01 as dd. I tried CAST(’01-‘+ month +’-‘+ year AS DATE) also CONVERT(DATETIME, ’01-‘+ month +’-‘+ year, 106) AS Both of them cause this error: […]

What is the statement to create a primary key in SQL like “3585c5d240dd4132bab35ab969137f3f”

I’m working with SQL Server Management Studio. I want to create a primary key like “3585c5d240dd4132bab35ab969137f3f” with a statement from SQL but I don’t know the statement to create a primary key. Can someone tell me what the statement is, to create a primary key like this?

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.