SQL Server variable columns name?

I am wondering why I cannot use variable column name like that: declare @a as varchar; set @a=’TEST’ select @a from x; Thank you

CodeIgniter MSSQL connection

I’m working on a web project that is to be deployed on a 64bit Windows 2008 Server machine running IIS 7.5 and PHP 5.3.8. The database on the system is Microsoft SQL Server 2008 R2. I’m developing the application on the CodeIgniter 2.1.0 framework, and I’m a bit stumped on getting it to connect to […]

Is it better to execute many sql commands with one connection, or reconnect every time?

Here’s my test code, which seems to suggest that it’s better to connect multiple times instead of connecting just once. Am I doing something wrong? int numIts = 100; Stopwatch sw = new Stopwatch(); sw.Start(); using (SqlConnection connection = new SqlConnection(connectionParameters)) { connection.Open(); for(int i = 0; i < numIts; i++) { SqlCommand command = […]

Check if SQL server (any version) is installed?

I need to find if SQL server is installed on a machine. It could be any version of SQL server (7, 2005,8, sql express etc). We need to know this information as we are writing an installer and need to show to the user that if SQL server has not been found, the installation cannot […]

How can I group by date time column without taking time into consideration

I have a bunch of product orders and I’m trying to group by the date and sum the quantity for that date. How can I group by the month/day/year without taking the time part into consideration? 3/8/2010 7:42:00 should be grouped with 3/8/2010 4:15:00

Unable to connect to localDB in VS2012 – “A network-related or instance-specific error occurred while establishing a connection to SQL Server…”

This is strange as I’m able to connect to localDB through SSMS 2008R2 with the same connection string (“Data Source=(LocalDB)\v11.0;Integrated Security=true“) Only C# code is unable to connect, I have tried increasing login time with Connect Timeout=60 but no luck. I have also tried specifying the database Initial Catalog=&lt;databasename&gt; where the <databasename> is the one […]

How to pass a null variable to a SQL Stored Procedure from C#.net code

Im calling a SQL stored procedure from a piece of C#.net code: SqlHelper.ExecuteDataset(sqlConnection, CommandType.StoredProcedure, STORED_PROC_NAME, sqlParameters); where the sqlParameters variable is defined as: SqlParameter[] sqlParameters = new SqlParameter[SQL_NUMBER_PARAMETERS]; Log.Logger.Debug(string.Format(“Running proc: {0} “, STORED_PROC_NAME)); SqlParameters[0] = new SqlParameter(“fieldID”, SqlDbType.BigInt ); SqlParameters[0].Value = fieldID; SqlParameters[0].Direction = ParameterDirection.Input; I need to now pass in another two parameters to […]

MS Excel – join external (SQL) data with local table (sheet)

I’m trying to get data from both external source and another sheet of my excel file into one table. What I have in SQL Server is a table of my customers: ╔════╦══════╦═════════╗ ║ ID ║ Name ║ Country ║ ╠════╬══════╬═════════╣ ║ 1 ║ Joe ║ Spain ║ ║ 2 ║ Bob ║ Frence ║ ║ […]

How do I find the data directory for a SQL Server instance?

We have a few huge databases (20GB+) which mostly contain static lookup data. Because our application executes joins against tables in these databases, they have to be part of each developers local SQL Server (i.e. they can’t be hosted on a central, shared database server). We plan on copying a canonical set of the actual […]

“CASE” statement within “WHERE” clause in SQL Server 2008

I am working with a query which contains “CASE” statement within “WHERE” clause. But SQL Server 2008 is giving some errors while executing it. Can anyone please help me with the correct query? Here is the query: SELECT tl.storenum ‘Store #’, co.ccnum ‘FuelFirst Card #’, co.dtentered ‘Date Entered’, CASE st.reasonid WHEN 1 THEN ‘Active’ WHEN […]

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