Archivo de la categoría: SQL Server

Bitacora de SQL Server

User, group, or role already exists in the current database

You moved the database to another instance and created a new login for this database instead of moving the login from the old instance to the new instance. I recommend that you read my article “How To Move Logins To Another Instance(sp_help_revlogin)”. You may receive this error when you want to authorize the login that you created for the database… Leer más »

SQL query to get start and end date from a result set

-1 I am working on one of requirement the raw data is in following format Requirement – Startdate should be the date when status changed to 1 and enddate should be the 1st date after the record status changed from 1 to any other number. Customer Status Date A123 0 7/2/2021 A123 0 7/15/2021 A123 0… Leer más »

SQL Query for Counting Records per Day

This SQL query will add up the record count per day based on a column called “Timestamp.” Transact SQL SELECT DATEPART(YEAR, Timestamp) AS ‘Year’, DATEPART(MONTH, Timestamp) AS ‘Month’, DATEPART(DAY, Timestamp) AS ‘Day’, COUNT(*) AS ‘Visits’FROM tblVisitsGROUP BY DATEPART(DAY, Timestamp), DATEPART(MONTH, Timestamp), DATEPART(YEAR, Timestamp)ORDER BY ‘Year’, ‘Month’, ‘Day’ Results The results of this query will appear… Leer más »