passing dynamic column name to a temp table not working?

I have this Sql puzzle i’m using Sql server 2005 the following query works fine DECLARE @query VARCHAR(200) DECLARE @colname varchar(50) CREATE TABLE #temp (ID INT IDENTITY PRIMARY KEY , value VARCHAR(50)) INSERT INTO #temp VALUES (‘first’) SET @colname = ‘myCol’ SET @query = ‘SELECT value AS’ + @colname + ‘ FROM #temp’ EXEC(@query) DROP […]

How to find records in a group by where only 1 field is different

I have 4 fields (empno,jobcode,abscode,unittype) and want to find all the records when only the unittype is different

How to map result from stored procedure to object

I’m using EF for fetching data from stored procedure in MS SQL. Stored procedure is returning table. (columns have same names as properties in my object) List<MyObject> result = db.ExecuteStoreQuery<MyObject>(“EXEC [dbo].myProcedure]”).ToList(); Is there a way how to do this without Entity Framework? (with SqlCommand) Thanks.

compile error CS0305 Using the generic type List

While csc /t:library strconcat.cs with using System.Collections.Generic; I get an error strconcat.cs(9,17): error CS0305: Using the generic type ‘System.Collections.Generic.List<T>’ requires ‘1’ type arguments mscorlib.dll: (Location of symbol related to previous error) The .cs code is taken from here: Using Common Language Runtime. I checked description on msdn but can’t compile till now using System; using […]

standard sql error message to console too vague

Is there a way to make console display of exception messages a little bit more precise in a c# winforms app. As in, instead of just; A first chance exception of type ‘System.Data.SqlClient.SqlException’ occurred in System.Data.dll Perhaps more like java’s, java.sql.SQLException: Closed Connection at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at … At least so I have an idea about […]

SQL Azure table relations

I have a simple database schema. Table TAGS and table USERS. How I can make a column in USERS table with List of TAGS ?

What does it mean to “Provide a table dump” in SQL Server

How can I perform a table dump to give to the client? To try and provide as much info: I am using both SQL 2005 and 2008 Existing databases are simple, like POS, Inventory, Tracking types I was asked to provide a table dump (of a certain table in a certain database in a certain […]

Using a SQL Table instead of a Dictionary Reference in C#

Right now I have all of my data that I need for my program stored in a separate class Tool and within that class their is a Dictionary<int, string> myTools. I have heard that for future use, it would be better to store this in a table within an SQL Database. Here’s what I have […]

sql query group by sql server

I have a sql server database table with columns as shown below : Table1 Id Name ErrorId 1 AB 2 CD 3 AB 3 4 AB 4 I want to get an output something like this : Name IdCount ErrorIdCount ErrorIds AB 3 2 4,3 CD 1 0 0 I wrote a query which looks […]

Error while changing the data type of the view column

create view [dbo].[view_name] as SELECT cast(Table1.col1 as bigint), Table1.col2, Table2.col3, cast(Table2.col4 as double) FROM Table1 INNER JOIN Table2 ON Table1.col1 = Table2.col1 Its showing error ” error on ‘)’” What is the error in the above query.I am using sql server 2008. edit create view [dbo].[SP_AHU_data] as SELECT cast(TrendLog.TrendLogId as bigint) as TrendLogid , TrendLog.TrendLogGuid, […]

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