tsql

TSQL - make a literal float value

I understand the host of issues in comparing floats, and lament their use in this case - but I'm not the table author and have only a small hurdle to climb... Someone has decided to use floats as you'd expect GUIDs to be used. I need to retrieve all the records with a specific float value. sp_help MyTable -- Column_name Type Comp...

How would I duplicate the Rank function in a Sql Server Compact Edition SELECT statement?

It doesn't look like SQL Server Compact Edition supports the RANK() function. (See Functions (SQL Server Compact Edition) at http://msdn.microsoft.com/en-us/library/ms174077(SQL.90).aspx). How would I duplicate the RANK() function in a SQL Server Compact Edition SELECT statement. (Please use Northwind.sdf for any sample select stateme...

help with t-sql self join

Based on the following table ID Date State ----------------------------- 1 06/10/2010 Complete 1 06/04/2010 Pending 2 06/06/2010 Active 2 06/05/2010 Pending I want the following ouptut ID Date State --------------------------- 1 06/04/2010 Complete 2 06/05/2010 Active So date is the ea...

How do I get the desired result in T-SQL like ....

How do I get the desired result in T-SQL like .... like I have a Record like UseriD InDate outDate 1 3/12/2010 3/12/2010 1 3/12/2010 3/13/2010 1 3/19/2010 3/30/2010 2 3/2/2010 3/3/2010 2 3/3/2010 3/4/2010 2 3/4/2010 3/29/2010 3 2/2/2010 2/28/2010 so...

UNIQUE CONSTRAINT on a column from foreign table in SQL Server 2008

I have two tables: create table [dbo].[Main] ( [ID] [int] identity(1,1) primary key not null, [No] [int] not null, [Sign] [char](1) not null ) create table [dbo].[Names] ( [ID_Main][int] primary key not null, [Name][nvarchar](128) not null, constraint [FK_Main_Users] foreign key ([ID_Main]) references [dbo].[Ma...

How to write stored procedure in SQL Server 2008 that generates 3 million random no

How to write stored procedure in SQL Server 2008 that generates 3 million random no in two columns in integer datatype. ...

i need to use string variable in the Proc in sql server database 2005

I have this procedure CREATE Proc [dbo].Salse_Ditail -- Add the parameters for the stored procedure here @Report_Form varchar(1) , @DateFrom datetime , @DateTo datetime , @COMPANYID varchar(3), @All varchar(1) , @All1 varchar(1) , @All2 varchar(1) , @All3 varchar(1) , @...

How to make an SQL query to get some specific range of rows from Table

How to make an SQL query if there are 30 records in table and I want to pick rows from 12 to 20 where 12 and 20 are row numbers not Ids. Ids Code 5 ABC 6 SDF 8 WSA 10 FSD 15 IOP . . . . 80 AWS ...

Have any idea about to add column by stored procedure?

I want to add column to table by stored procedure and the name of column should be parameter.'s value. ...

Conversion failed: SqlParameter and DateTime

I'm changing old, vulnerable SqlCommands with SqlParameters but get a SqlException: System.Data.SqlClient.SqlException {"Conversion failed when converting datetime from character string."} on sqlCommand.ExecuteScalar: Dim sqlString As String = _ "SELECT TOP 1 " & _ "fiSL " & _ "FROM " & _ "tabData AS D " & ...

T-SQL - how to get around the order by restriction in CTEs

Hi all I have the following CTE. Its purpose is to provide unique Month/Year pairs. Later code will use the CTE to produce a concatenated string list of the Month/Year pairs. ;WITH tblStoredWillsInPeriod AS ( SELECT DISTINCT Kctc.GetMonthAndYearString(DateWillReceived) Month FROM Kctc.StoredWills WHERE DateWillReceived BETW...

How do I iterate through hierarchical data in a Sql Server 2005 stored proc?

Hi, I have a SqlServer2005 table "Group" similar to the following: Id (PK, int) Name (varchar(50)) ParentId (int) where ParentId refers to another Id in the Group table. This is used to model hierarchical groups such as: Group 1 (id = 1, parentid = null) +--Group 2 (id = 2, parentid = 1) +--Group 3 (id = 3, parentid = 1) ...

Data Access from single table in sql server 2005 is too slow

Following is the script of table. Accessing data from this table is too slow. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Emails]( [id] [int] IDENTITY(1,1) NOT NULL, [datecreated] [datetime] NULL CONSTRAINT [DF_Emails_datecreated] DEFAULT (getdate()), [UID] [nvarchar](250) COLLATE Latin1_Ge...

Drop all foreign keys in a table

I had this script which worked in sql server 2005 -- t-sql scriptlet to drop all constraints on a table DECLARE @database nvarchar(50) DECLARE @table nvarchar(50) set @database = 'dotnetnuke' set @table = 'tabs' DECLARE @sql nvarchar(255) WHILE EXISTS(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_catalog = @datab...

SQL Server 2005 Reporting Services: How to count rows that are not null? Any hints for calculating totals?

Using Reporting Services in SQL Server 2005: Is there a way to count only records that are not null; similar to "COUNTA" in Excel? I would think this would be very simple process, but nothing I have tried has worked. For example, I have tried using the following expression for "Completed", which is one column I am trying to count: =count...

TSQL: Call a stored procedure from another stored procedure and read the result

Hi, I have a stored procedure that, ending with a SELECT, returns a recordset. I can call it within anoher stored procedure like this: EXEC procedure @param How to get the returning recordset? Thanks ...

Using ADO.NET Entities LINQ Provider to model complex SQL Queries?

What I find really powerful in ADO.NET Entities or LINQ to SQL, is the ability to model complex queries. I really don't need the mappings that Entities or LINQ to SQL are doing for me - I just need the ability to model complex expressions that can be translated into T-SQL. My question is - am I abusing too much? Can I use the Entity Fra...

Matrix Transpose TSQL

Can we do matrix transpose (rows become columns and columns become rows) in standard SQL2005/2008? 1 2 3 4 5 4 5 6 6 7 7 8 9 8 9 1 3 4 5 6 2 4 5 6 7 changes to 1 4 7 1 2 2 5 8 3 4 3 6 9 5 6 4 6 8 5 6 5 7 9 6 7 how about no of rows <> no of column ? let's consider the no of rows it's fixed. ...

Question about inserting/updating rows with SQL Server (ASP.NET MVC)

I have a very big table with a lot of rows, every row has stats for every user for certain days. And obviously I don't have any stats for future. So to update the stats I use UPDATE Stats SET Visits=@val WHERE ... a lot of conditions ... AND Date=@Today But what if the row doesn't exist? I'd have to use INSERT INTO Stats (...) VALUES...

retrieving second most highest value from the table

how do i retrieve the second highest value from the table ...