Lot of full table scans (around 600) because of a simple IN statement

I have 2 CTE in my query. In the end of the query I simply join them and write the result to a page. On the page I have filter options so when I have filters I have to put a trivial IN statement to the end of the query. When I don’t have the […]

Cancel long running IFRAMEs

I have an ASP.NET WebForm application – a main page that hosts a bunch of IFRAME “widgets”. When main page loads – the widgets’ pages load as well and begin their own processing, which include connecting to SQL Server to run stored procedures. What would be the best way to cancel those IFRAME processing should […]

How to update table with dynamic table name?

I want to update table columns which is generated dynamically. I tried this ALTER PROCEDURE [dbo].[spname] @Id INT , @Flag varchar(MAX), @TableName nvarchar(max) , AS BEGIN IF(@Flag=’Process’) BEGIN DECLARE @squery nvarchar(max) = ” IF EXISTS(SELECT NAME FROM [DZ_REPO].SYS.TABLES WHERE NAME = @TABLENAME) BEGIN set @squery = ‘use [DZ_REPO]’ set @squery += ‘UPDATE A SET A.cFirstName=B.FN, […]

No nvarchar: “Operand data type nvarchar is invalid for sum operator”

I have a view that returns ProductName, Qty, and other columns Defined as: SELECT ProductName, Qty, /* etc. */ FROM SomeConcreteTable SomeConcreteTable defines ProductName as nvarchar(40) and Qty as float. SELECT ProductName, SUM(Qty) FROM MyView GROUP BY ProductName This causes an error Operand data type nvarchar is invalid for sum operator When the view returns […]

Running SQL script in SqlCmd with SQL Server Express

I have developed a C# application connecting to a SQL Server database. I now wish to test the application on the client PC, and so I scripted the database and now wish to deploy it on the client PC. The client PC is running SQL Server Express, however SQL Server Management Studio is not installed […]

Append Quotes for all VARCHAR Columns when exporting to csv file

I have a stored procedure which when run gives a table output. I want to export this procedure to a csv file but want to append double/single quotes for all the columns with a datatype CHAR/VARCHAR. For Example: Stored Proc O/P: ID Name Address SSN 1 abd 9301,LeeHwy, 22031 64279100 Output in CSV File: 1,”abd”,”9301,LeeHwy, […]

Uses of Index in SQL server

I’m new to Index Constraints in SQL Server… Can anybody instruct me to clear my doubt… I’ve created an Index named EmpName by using the EName as ColumnName. Create index EmpName on Users_Info (EName) How can I check the use of created Index in the SQL???? And I wanna know the difference of search results […]

Retrieve records falling within a daily time range across a given month

My table contains fields that store ticket sale date/time price I need help on how to select only those tickets sold between 8:00 AM and 12:00 PM on a day-to-day basis for an entire month, without including any sales between 12:01 PM and 10:00 PM.

Include milliseconds in sql query from C#

I am currently using SqlDataAdapter to query a SQL database: SqlCommand myCommand = new SqlCommand(); myCommand.Connection = myConnection; string cmd = @”select * from dbo.Table where errordate > ‘2015-05-29′”; myConnection.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd, sqlConn); da.Fill(dt); The query is working fine but the only problem is that The date column does not include milliseconds. […]

Invalid Column name for a Temporary table column in a stored procedure

I have a stored procedure inside of which a temporary table is created: I get an error that says: Invalid column name ‘ValFromUser’. Why is that? Why do I get this error only for ValFromuser but no other column?How I may get rid of this? CREATE Procedure [dbo].[OutputProcedure] –declarations here AS BEGIN SET NOCOUNT ON […]

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