Tag: ssms

T-SQL – Get runduration from a restore job

I’m using the code below to pull 3 columns: Server Name Database Name Date/Time Restore started Code: WITH LastRestores AS ( SELECT @@SERVERNAME AS [ServerName], [d].[name] AS [DatabaseName], CONVERT(VARCHAR, r.restore_date, 100) AS [RestoreDateTime], RowNum = ROW_NUMBER() OVER (PARTITION BY d.NAME ORDER BY r.[restore_date] DESC) FROM master.sys.databases d LEFT OUTER JOIN msdb.dbo.[restorehistory] r ON r.[destination_database_name] = […]

SSMS Rank() function. How can partition by a range of values rather than an exact value?

I’m using a rank() and a row_number() function in some sql code. Everything is working fine except for parts where I have records that have [np_Exposure_Total] values as 20134446 vs. 20134447. I want these to essentially be treated as if they were the same number. I’m thinking ideally I would like to do it by […]

How to hide security node and logins from some users in SQL?

We are using SQL Server 2012. I’m granting access to some one from out side my company. I hide all Databases except his one. Is there any possible way to hide all users and logins? We want him to have information as few as possible about our server at SSMS. How can we do this?

SQL JOIN doubling values

I have two temp tables with following data: temp_aht temp_1 I use this query to join the two tables on column Incident: Select count(distinct a.Incident) as nr_of_tickets ,a.[Service] ,SUM(CASE WHEN a.status_switch IN (‘Assigned » In Progress’,’Assigned » Pending’,’Assigned » Resolved’,’Assigned » Closed’) THEN a.TotalSeconds ELSE NULL END) AS AssignedTime ,SUM(CASE WHEN a.status_switch IN (‘In Progress […]

Not Nullable fields in SQL Server Still Considered Required Fields in ASP.NET MVC

I have a non nullable fields in a table with default values set already in the property “Default Value or Binding” in SSMS. I linked this table in an ASP.Net mvc application. When I created the view and when running the create view, it still asking me to enter the required fields for the non […]

SQL Server: How to attach / repair a detached / damaged database?

A database server crashed. I was able to get the mdf and the log file and I am trying to mount it on another server. I don’t have backup as it was a development database. When I try to attach the mdf and ldf files, Sql Server Management Studio give me this error: TITLE: Microsoft […]

I can not save my user defined function in my Database in sql server 2012

I am using SQL server 2012. Actually, I am new one in relational database sphere. I create function in my DB but I can’t save it in my Project (current database). How can I save it to my DB and then I need call this function by query? I just press “save” button and sql […]

don`t understand how trigger works

Trigger should react to deleting row from table Suppliers if there is some supplies in the table Supplies from this supplier, trigger should cancel deleting. This code allows to delete both, suppliers with supplies and suppliers without supply: CREATE TRIGGER SuppliersDeleteCondition ON Suppliers FOR DELETE AS IF EXISTS ( SELECT 1 FROM Supplies Ses JOIN […]

invalid parameter 1 specified for datadiff

I want to update field everyday automatically in database about duration. the formula is (due date – date now). I want to use sql server agent. But when I test the job its failed. USE FacilityMonitoring GO UPDATE [dbo].[klaim] SET selisihint = DATEDIFF (“dd”, GETDATE(), durasi_end) GO Query in SQL Server agent: Error:

Connecting to SQL Server Database using a Hosted Web Application

I have created a .net web application using c# that inserts, updates, and deletes data from an SQL server database. I have tested it using my localhost and it works fine. Now I would like to publish this application on a hosted site. My question is, does the database need to be on the same […]

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