Tag: stored-procedures

Take average of only most recent group

There’s one table named StudentScore which has fields of: Score, CourseID, StudentID and Semester. The later three ones are the primary keys. I want to write a stored procedure to get the average score of each student. But the rule is quite complex and I don’t know how to express it in one query. Nested […]

Splitting text in SQL Server stored procedure

I’m working with a database, where one of the fields I extract is something like: 1-117 3-134 3-133 Each of these number sets represents a different set of data in another table. Taking 1-117 as an example, 1 = equipment ID, and 117 = equipment settings. I have another table from which I need to […]

SQL Server / T-SQL need to modify dynamic stored procedure?

I have a stored procedure that dynamically generates MERGE TSQL statements to handle SCD Type 1 updates between the given Dimension / Staging table dump. Here is the T-SQL code (modified from the original code by Alex Whittles): USE [OPPY_DWUSD] GO ALTER PROCEDURE [dbo].[GenerateMerge] /*************************************************************** * * * Script for use with blog post * […]

SQL Server stored procedure no statements run when from RPC

I have a SQL Server 2000 database with a stored procedure that deletes a row from a specific table, given its id. When I call the stored procedure from VB.NET, it does not delete the row, but running the same script directly on the database via SSMS, it works. Here’s my chain of events: Start […]

Counting records with a specific date value

I want to get all records entered with specific day, for example today: ALTER PROCEDURE [dbo].[SP_GET_QUEUESINFO_BY_DATE] @date nvarchar = ‘2012-09-21’ AS BEGIN declare @dateStart nvarchar(50) = @date + ‘ 00:00:00.0’ declare @dateEnd nvarchar(50) = @date + ‘ 23:59:59.437’; declare @returnData table (allQueue int,inQueue int,outQueue int) SELECT ‘table1’ as table_name, COUNT(*) FROM Queue as Counts UNION […]

SQL query won't work when used from a stored procedure

I got a question about these two queries. The first one does work, the second one does not. I know I’m missing something, I can’t see it though! SELECT Kod10 FROM Adminview WHERE Kvartal = 1 AND Användarnamn = ‘LOLGATAN13’ AND År = ‘2013’ And this is the stored procedure ALTER PROCEDURE [dbo].[Checkinpvalue] @Inmånad varchar(50), […]

SQL Server stored procedure solution

I have a stored procedure which returns two columns Start and end dates. What will be stored procedure to convert into distinct dates list which include all of the dates in between as well. Examples of Events: StartDate EndDate • 1/2/2012 6:00 – 1/2/2012 9:00 • 1/2/2012 11:00 – 1/2/2012 19:00 • 1/1/2012 11:00 – […]

Join 4 tables across 2 databases

TB1, TB2, TB3 are in one database on the server and TB4 is on another database. The column information needed for the join are as follows: TB1 – column a1, b2. TB2 – column a2, b2, c3. TB3 – column a3. TB4 – column a4. TB1, TB2, TB3 are related by ID TB1’s ID is […]

Can't insert a second row into a table though it insert first row by stored procedure

It inserted a first row successfully but it’s not inserting any other row, though second row has no conflict of primary key Code in my aspx.cs file: outputParVal = sqlCmd.Parameters[outputParName].Value; outparameter in stored procedure is— “Result” CREATE PROCEDURE [dbo].[RecruiterProfileInsert] @CompanyId int, @CompanyName varchar(200), @EmailId varchar(50) , @Password varchar(20) , @ContactNumber varchar(15), @Website varchar(50), @CompanyProfile varchar(2000), […]

Why do I get `Procedure or function expects parameter`?

I’m inserting a row into a SQL Server 2005 database table from Classic ASP. I get the following error: Procedure or function ‘replace_matl_form_insert’ expects parameter ‘@matl_no’, which was not supplied. I am supplying the parameter. The types match, and I’m still getting that error. Here is the classic asp code which is used to insert […]

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