How can get the stored procedure execution logs?

I know that how many times it was executed from execution_count in sys.dm_exec_procedure_stats. But how these values are calculated? Is there any way to know how these values get calculated? I want whole log when the stored procedure was first time executed to till last_execution_time logs.

Can I use output variables to get a value?

I have a stored procedure where I’m checking if username exists and if it does not exists insert into user table then gets userid for the same username. I was trying to use an output variable to get the userid. Am I going about this wrong? alter Procedure Check_User_Name ( @username varchar(25), @password varchar(100), @role_id […]

Parent-Child without FK inserting in wrong order

I have a legacy SQL Server database I’m in no position to significantly change for many reasons. There is a parent/child relationship between two tables. There are no foreign keys between these two tables. There is also a FOR INSERT trigger in the child table that checks for the existence of a parent record. If […]

SQL: SELECT DISTINCT not returning distinct values

The code below is supposed to return unique records in the lp_num field from the subquery to then be used in the outer query, but I am still getting multiples of the lp_num field. A ReferenceNumber can have multiple ApptDate records, but each lp_num can only have 1 rf_num. That’s why I tried to retrieve […]

SQL – After Update Trigger – How to add timestamp when column value changes to specific Value

I want create a Trigger to update the column dbo.tbl_dispatching.Actual_Pickup_Time with timestamp when the below column is updated to 5 dbo.tbl_dispatching.Status_ID = “5” And update dbo.tbl_dispatching.Actual_Delivery_Time with timestamp when the below column is updated to 8 dbo.tbl_dispatching.Status_ID = “8” I have done this so far and not sure how to complete it: CREATE TRIGGER Delay_Timestamp […]

Reset Auto Increment by day in visual studio – SQL

I´m looking for an solution to reset the auto increment id by day change. Let’s say you have a order and you want to store 2 identification numbers… the daylie order number and the order itself. E.g. ORDER#123123 ORDERDAY#3 Article#Something, etc. The order number will be auto increment and primary while the day id will […]

SQL Server – Selecting columns with two matching other columns

I have a table like so: columna int columnb int Some sample data: columna columnb 1 1 1 2 1 3 2 1 2 2 2 4 3 1 3 3 3 7 4 3 5 2 5 3 I want to select columna where the same value for columna has both 1 and 3 […]

How to evaluate a condition on a large number of database records

I have a datamodel in Entity Framework CodeFirst. This datamodel contains a Contracts entity of which there are about half a million records present in SQL Server. A Contract entity is related to other entities, directly of indirectly. I now have a backend job that needs to check all contracts for a condition and if […]

Error In Stored Procedure with error message as There is already an object named

Please help me to debug the error for below stored Procedure. Whenevere i tried to execute the sp i am getting error as (142 row(s) affected) Msg 2714, Level 16, State 6, Line 16 There is already an object named ‘AOP_Monthly_GrowthRate_Acquisition’ in the database. if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = ‘AOP_Monthly_GrowthRate_Acquisition’ AND […]

How can I make a SQL (Query) that is set as a record source in a form to be called once?

Background: working with MS Access as a front end and SQL Server as a back end to organize data of every student found in a school. Well I’ve been working on MS Access forms and I’ve set the record source as a query and set the intended text boxes , combo boxes , etc… to […]

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