sql-server

Simple calculation in SQL Server

I got a distance field in my database that stores the distance traveled on a specific route. I need to select all the distance fields and plus them together, then returning the result from my stored procedure. How can this be done? ...

How can i create this time-table with stable time format?

How can i get result "My Dream Table Result" CREATE TABLE #temp( [count] int, [Time] nvarchar(50) ) DECLARE @DateNow DATETIME,@i int SET @DateNow='00:00' set @i=1; while(@i<1440) begin set @DateNow=DATEADD(minute, 1, @DateNow) insert into #temp ([count], [Time]) values(0,@DateNow) set @i=@i+1 end ...

Adding a new role to existing User SQL server 2008

Hi, I'm attaching a new database programatically using VB.net application. I wrote DB scripts and execute them using command object. After attaching the db, I have to create logins and add roles. If the login am going to create is already existing on that target SQL server then am just adding the roles using (EXEC SP_addrolemember), pro...

concatenate two fields in a dropdown

in an sql table there's an id, first name and last name field. i'd like to concatenate the first and the last name fields and display it as one in a dropdown control. this is the vb.net code: con() sqry = "[SELECT QUERY]" sqcom = New SqlCommand(sqry, sqcon) da.SelectCommand = sqcom ds.Clear() da.Fill(ds) ddl_a...

Build and display a complex composite primary key in a column

I need to build a primary key consisting of 3 sections. The first section is 3 letters long and must be an a followed by two digits eg "a00" The second section is a 3 digit unique identifier INCLUDING LEADING ZEROES, example "003" The third section is the year section of the date, eg "2008" This is all separated with dashes, so a com...

How can i left out join these #temp (default data) and another table?

i try to generate a table (look TABLE 1) with the query(below). CREATE TABLE #temp( [VisitingCount] int, [Time] nvarchar(50) ) DECLARE @DateNow DATETIME,@i int SET @DateNow='00:00' set @i=1; while(@i<1440) begin set @DateNow=DATEADD(minute, 1, @DateNow) insert into #temp ([VisitingCount], [Time]) values(0, right(left(conv...

How to convert datatable from UDF in SQL?

This Codes give me error:Msg 156, Level 15, State 1, Procedure DefaultActivity, Line 2 Incorrect syntax near the keyword 'RETURN'. Msg 137, Level 15, State 2, Procedure DefaultActivity, Line 3 Must declare the scalar variable "@returnTable". Msg 1087, Level 15, State 2, Procedure DefaultActivity, Line 18 Must declare the table variable "...

Dealing with large result sets in SQL Server Analysis Services

I have a Database that contains data about articles,structures and manufacturers. Meaning an article is linked to 1 manufacturer and to N structure-nodes (think as article-classification-nodes). Querying articles using T-SQL with a lot of conditions is currently too slow to be usable for an e-shop, even with good hardware and properly i...

Last added records in SQL-Server table

Is it possible to see when a record has been inserted in a SQL table without using a datetime column? ...

ColdFusion - Inserting form field into SQL Server MONEY

I'm trying to insert a value from a form field into a SQL Server MONEY field using ColdFusion. If the amount is just dollars, or if the cents are more than 12, the insert goes fine. But if the cents amount is less than 12, according to the error that's thrown, the system appears to be converting the money amount into a date format befor...

SQL query to extract text from a column and store it to a different column in the same record.

I need some help with a SQL query... I have a SQL table that holds in a column details of a form that has been submitted. I need to get a part of the text that is stored in that column and put it into a different column on the same row. The bit of text that I need to copy is always in the same position in the column. Any help would b...

What causes Timeout expired SqlExceptions in LINQ to SQL?

My application keeps running into Timeout Expired SqlExceptions. The thing is that this query is one that will simply have to run for a decent amount of time. I'm having trouble figuring out where this exception is occurring though. Is this a timeout that's created at the database server or is it happening in my program? Or if it cou...

SQL testing best practice

Hi, What is the best practice for SQL testing (stored procedures, views, queries, triggers...) excluding automated testing? Most of the time a query works or returns thousands of rows, so it is a bit difficult to check them. I want to know how you usually do the testing of a SQL query. Can you point me to a good (online) reference? ...

CLR UDF returning Varbinary(MAX)

Is it possible for a SQL CLR User-Defined Function to return the data type varbinary(MAX)? In the documentation it mentions: "The input parameters and the type returned from a scalar-valued function can be any of the scalar data types supported by SQL Server, except rowversion, text, ntext, image, timestamp, table, or cursor." - they d...

can sql server reporting services be used as a report writer?

Hi, we are trying to create reports programmatically in asp.net using microsoft reporting services. We are not sure if it is possible though. We have several queries for our reports. Instead of creating a separate .rdlc report for each of those queries, we are looking for a way so that we can feed the query / stored procedure to the rep...

T/SQL Puzzle - How to join to create one-to-one relationship for two unrelated tables?

Let's assume that I have two tables... Foo and Bar. They contain the following data. Table Foo: Foo_Id ------ 100 101 Table Bar: Bar_Id ------ 200 201 As you can see, each table has two records. I'd like to join these tables together in a way where they return two records; the ultimate goal is to create a one to one relationship f...

add SQL Server index but how to recompile only affected stored procedures?

I need to add an index to a table, and I want to recompile only/all the stored procedures that make reference to this table. Is there any quick and easy way? EDIT: from SQL Server 2005 Books Online, Recompiling Stored Procedures: As a database is changed by such actions as adding indexes or changing data in indexed columns, the origi...

How can I execute a set of .SQL files from within SSMS?

How could I execute a set of .SQL files (each does some data transformations) from within SQL Server Management Studio? What other alternative are there for executing .SQL files in batch? ...

How do I create an SQL query that groups by value ranges

I would like to create a sql query that reports the percentage of results in a particular range. for instance 20% of the values between 10 to 20 40% of the values between 20 to 32.5 Server - MSSQL ...

What is the equivalent for LOCK_ESCALATION = TABLE in SQL Server 2005?

I have a script that was generated in SQL Server 2008, but I need to execute it against a SQL Server 2005 database. What would an equivalent statement for the following be in SQL Server 2005? ALTER TABLE dbo.Event SET (LOCK_ESCALATION = TABLE) ...