[Solved] An unhandled exception of type ‘System.InvalidOperationException’ occurred in System.Data.dll?

You should either use this method: SqlCommand cmd = new SqlCommand(“dbo.workScheduleDataGrid”, sqlcon); or this method SqlCommand cmd = sqlcon.CreateCommand(); to create the command, but not both (the second assignment in your code overwrites the first one). With the second options, you need to specify the command to execute separarely: cmd.CommandText = “dbo.workScheduleDataGrid”; Also, do not … Read more

[Solved] Insert into Temp Table from SQL Dynamic Results

all what i had to do is add this: ‘ into ##myTempTable DECLARE @DynamicPivotQuery AS NVARCHAR(MAX) DECLARE @ColumnName AS NVARCHAR(MAX) –Get distinct values of the PIVOT Column SELECT @ColumnName = ISNULL(@ColumnName + ‘,’,”) + QUOTENAME([month]) FROM (SELECT DISTINCT [Month] FROM MyTable) AS [Month] order by [month] –Prepare the PIVOT query using the dynamic SET @DynamicPivotQuery … Read more

[Solved] Convert SQL Query To LINQ?

I didn’t test it, but it should look something like that : var query = (from s in Suppliers select new { SupplierId = s.SupplierId, CompanyName = s.CompanyName, ContactPerson = s.ContactPerson, Address = s.Address, Email = s.Email, InActive = s.InActive, BranchId = s.BranchId, CreateDate = s.CreateDate, CreatedBy = s.CreatedBy, UpdateDate = s.UpdateDate, UpdateBy = s.UpdatedBy, … Read more

[Solved] How do I join on multiple columns in SQL Server and include columns in one table that aren’t present in other tables?

declare @t1 table ( col_a varchar(5) null ,col_b varchar(5) null ,col_c varchar(5) null ,col_d varchar(5) null ) declare @t2 table ( col_a varchar(5) null ,col_b varchar(5) null ,col_e varchar(5) null ) insert into @t1 values (‘Cat 1′,’Bla a’,’C-1′,’D-1′) ,(‘Cat 1′,’Bla a’,’C-2′,’D-2′) ,(‘Cat 1′,’Bla a’,’C-3′,’D-3′) ,(‘Cat 2′,’Bla b’,’C-4′,’D-4′) ,(‘Cat 2′,’Bla b’,’C-5′,’D-5′) insert into @t2 values (‘Cat … Read more

[Solved] Find number of rows of each column name [duplicate]

Assuming that there aren’t any partitioned table: USE [SpecificDatabank] SELECT sys.columns.name AS ColumnName, sys.tables.name AS TableName, sys.partitions.rows AS [Rows] FROM sys.columns JOIN sys.tables ON sys.columns.object_id = sys.tables.object_id JOIN sys.partitions ON sys.tables.object_id = sys.partitions.object_id and sys.partitions.index_id in (0,1) WHERE sys.columns.name LIKE ‘%ColumnName%’ 1 solved Find number of rows of each column name [duplicate]

[Solved] DELETE duplicate values in SQL

I’ll take a stab at your problem. This is only a guess, based on the query you provided. A complete question would have described what exactly you mean by a duplicate row. delete from Registrations where exists ( select 1 from Registrations r2 where r2.UserItemId = Registrations.UserItemId and r2.CourseOfferingId = Registrations.CourseOfferingId and r2.Id < Registrations.Id … Read more