SQL query for Java code

I found this example how to list SQL server backup dates http://www.sqlmatters.com/Articles/Checking%20when%20a%20database%20was%20last%20backed%20up.aspx SQL Query: ;WITH CTE_Backup AS ( SELECT database_name,backup_start_date,type,physical_device_name ,Row_Number() OVER(PARTITION BY database_name,BS.type ORDER BY backup_start_date DESC) AS RowNum FROM msdb..backupset BS JOIN msdb.dbo.backupmediafamily BMF ON BS.media_set_id=BMF.media_set_id ) SELECT D.name ,ISNULL(CONVERT(VARCHAR,backup_start_date),’No backups’) AS last_backup_time ,D.recovery_model_desc ,state_desc, CASE WHEN type =’D’ THEN ‘Full database’ WHEN […]

Debugger in SQL Server 2008 R2

I am using SQL Server 2008 R2 Management Studio for an old database that is SQL Server 2005 based. I want to debug my T-SQL code but SQL Server is telling me: the transact-sql debugger does not support SQL Server 2005 or earlier versions of SQL Server What can I do for debugging that T-SQL […]

How to create a compound index in SQL Server?

I have a requirement in which I need to create a compound index name advisor_name on the Employee table where Advisor Name = Last_Name + “, ” + First_Name

Update query to find and change portion of MS SQL DateTime

I have various datetime stamps on a expiration field (datetime). The datetime in that field for each record varies. For example, 2015-12-31 04:59:00:000, 2014-12-31 17:00:00:000, 2020-12-15 04:00:00:000 Trying to write a query to find all datetime that have an ENDING that is not equal != to 05:00:00:000. Then an update query to update the end […]

Decipher SQL Server page storage

CREATE TABLE tbl ( col1 VARCHAR(1) ) INSERT INTO tbl VALUES (NULL) DBCC traceon(3604) DBCC ind(0, tbl, -1) DBCC page(0, 1, 290, 3) WITH tableresults /*Change page number as required*/ Output PAGE HEADER: Slot 0 Offset 0x60 Length 9 Record Type PRIMARY_RECORD PAGE HEADER: Slot 0 Offset 0x60 Length 9 Record Attributes NULL_BITMAP PAGE HEADER: […]

ServiceStack not using custom converter for NodaTime.Instant

In an effort to improve performance, I recently added some denormalized SQL views to our database and created some query models that correlate. Everything is working great except for one thing — ServiceStack Ormlite isn’t using my custom type converter for some of the query model fields and I can’t figure out why. What’s really […]

SQL Server Update using PYODBC

I have a CSV file which contains ‘\N’ in some cells under a column for which the header is defined as int in SQL Server. I am using pyodbc to update the SQL server data each day from the CSV supplied. The problem is whenever I have ‘\N’ in the CSV file then the SQL […]

Is it safe to perform a long action in a separate thread?

I’m dealing with a CSV file that’s being imported Client side. This CSV is supposed to contain some information which will be destinated to perform an update in one of the tables of my company’s database. My C# function process the file, looking for errors and, if no errors were found, it sends a bunch […]

Incremental Load Issue

I have a query like so: SELECT Col1, Col2, Col3, ColDate FROM TableA WHERE DAY(ColDate) = 1 AND MONTH(ColDate) = MONTH(CASE WHEN DATEPART(HOUR, GETDATE()) < 16 THEN GETDATE() – 1 ELSE GETDATE()END) AND YEAR(ColDate) = YEAR(CASE WHEN DATEPART(HOUR, GETDATE()) < 16 THEN GETDATE() – 1 ELSE GETDATE()END) The query above pulls data daily into another […]

Exclude db in simple recovery mode from t-log backup

We have a T-log Maintenance plan for few databases. One of the database “ABC” in simple recovery mode. Our maintenance plan fails with the error “Database ABC will not be backed up because it does not have recovery mode set to full or bulk” Please help me fix this issue without changing ABC database to […]

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