sql-server-2005

Recursive CTE to find parent records

Hello, first i must admit that i'm not very familiar with sql server's recursive CTE's but i think this is the best approach. I have a table tabData. Its PK is named idData and there is a self referencing FK fiData. So fiData references the parent record and SELECT * FROM tabData WHERE idData=fiData returns all data of the parent. T...

Wrong order in Table valued Function(keep "order" of a recursive CTE)

Hello, a few minutes ago i asked here how to get parent records with a recursive CTE. This works now, but I get the wrong order(backwards, ordered by the PK idData) when i create a Table valued Function which returns all parents. I cannot order directly because i need the logical order provided by the CTE. This gives the correct order(f...

Complex editing on a gridview in C#

Hi all, I am working on an attendance system that has the following tables: Entry +---------+-----------+ + EntryID + EntryDate + +---------+ ----------+ Hour +---------+--------+---------+ + EntryID + InHour + OutHour + +---------+--------+---------+ With the following example data: Entry +---------+---------------------+ + En...

sql nested select invalid column

Hey all, I've been struggling with a select statement for a bit now and I was hoping to get some help. I currently have a list IPs in a temporary table and I want to calculate how many times this IP acts as a server and how many times it acts as a client. No matter how I manipluate this select statement I always get the same error ...

Update all SQL NULL values in multiple columns using Column level WHERE clause?

We have a database with a bunch of wide tables (40-80 columns each) and just found a bug that introduced NULL values into about 500 of the records. The NULL values can appear in any of the columns (all are integer columns, see image below) but these NULL values are causing issues with one of our reporting systems that cannot be changed e...

Generate script Insert in .net

Hi all, I have problem when trying generate script insert with specific condition. So far I am already trying this step. Add references Microsoft.SqlServer.ConnectionInfo and Microsoft.SqlServer.Smo Add reference in code Microsoft.SqlServer.Management.Smo Add this to script. var srv = new Server(@"localhost\SQLEXPRESS"); var db ...

Restore database from database using script

I'm looking for a simple script that I can use to overwrite one database with another one. We have a master db with master schema and data and every so often a developer wants to blow away his messed up db with a complete overwrite from the master. I currently accomplish this with SQL Server Studio and the GUI controls but I want somethi...

Database mirroring and replication on SQL Server 2005

How can I configure my mirror database to publish its data to the same replication database that my primary has ( I need to take my primary database offline for maintenance purposes.)? ...

Which edition of SQL Server 2008 should I install on dev machine?

Which edition of SQL Server 2008 should I install for development purposes? I'm presuming the developer edition, but... What I do is (SQL Server 2005 until now): Develop databases to plonk onto our web server (that runs SQL Server Express) Manage and extend these database using the SSMS (SQL Server Management Studio) Develop SQL Se...

SQL TOTAL AND GRAND TOTAL

hEY ALL i have a table that shows transactions and their status. How can i create a column that shows the total of transactions that are completed,rejected,declined and the grand total of all on a different column for example i am looking something like this Completed 100 Rejected 50 Declined 20 Total 170 In 3 different rows...

SQL Server: Boolean expressions with subquery in WHERE-clause

Hi! I have a subquery within a WHERE-clause within a subquery. Notwithstanding the design issues of the database (not my job), I am getting some strange errors when trying to extend the top level WHERE-clause in this expression. The example below WORKS. LEFT OUTER JOIN CargoVoyageLocation on CargoVoyageLocation.VoyageLocationI...

Extremely slow Table-Valued-Function with recursive CTE inside.

Hello, I've cretaed a TVF which returns a table with parent-records from a recursive CTE here. That works excellent and the result is available directly. Now i wanted to get the child-records(they have the same FK as the current record's PK). The problem is that it takes 1:10 minutes to get 22 child-records for a given id. Why is this s...

Repeat footer field on new page

The question is simple, I couldn't find any solution though. If it is possible, how do I repeat a field that's in the Footer on a new page if it doesn't fit the container? For example: I have a column that can store up to 5000 characters, and I must display it in the Footer. So if it reachs a certain number of characters, I'd like it t...

Complex SQL I don't want to convert in a stored procedure

Hi all! I would like to have your assistance in order to know if it's possible to achieve the desired query without needing a stored procedure. I will try to explain myself as good as I can. I have a similar structure to this: PK / FK / DateTime / Value 1 / 68 / 10:30 / 60.5 2 / 68 / 09:30 / 10.5 3 / 61 / 05:30 / 01.0 4 /...

SQL Server deadlock while inserting rows in a table

Hi, The topic of sql server deadlock has been discussed many times, however, I was unsure that even two simultaneous inserts on a table can end up in a deadlock situation. Scenario: While testing our application (SQL Server 2005 as backend, ASP.net 3.5) we inserted records into a table simultaneously (simplified overview) and that resu...

Altering results prior to using SQLContext.Pipe.Send() in a .NET sproc

Is it possible to edit the data returned from command.ExecuteReader, and then return that to SqlContext.Pipe.Send()? Are there any forseeable issues (I have to reset the cursor to the beginning)? I have a .NET stored procedure that will query a table like this (code from MSDN) public class StoredProcedures { /// <summary> ///...

TSQL - SET vs. SELECT when assigning variables?

What are the differences between SET vs. SELECT statement when assigning variables in T-SQL? ...

Developer: how to get reporting data from about 20 databases?

I'm a junior developer in our team. In one project we have about twenty databases in one SQL Server instance. We have db_owner rights to these databases. My intention is to monitor certain things from these databases (e.g. file size). But because we don't have sysadmin rights, we don't have all those management tools for these database...

Find and replace a string in sql server 2005

I am supposed to remove the following from the address field. Replace all words named as 'Flat' to empty space, also remove the number that comes along with it. eg. I have word called as 'Flat 234 5th Street'. It should be replaced as 5th Street. I gave the query as select ltrim(rtrim( substring ('Flat 123 5th Street', cha...

Problem with ASP Repeater and SQL Data Source

Hi! Here's my data table in my SQL DB, and below that is the code for my Repeater control: ArticleID int NOT NULL, ArticleTitle varchar(100) NOT NULL, ArticleCategory int NOT NULL, ArticleDate datetime NOT NULL, ArticleContent text NOT NULL, DeletedYN char(3) NOT NULL <asp:Repeater runat="server" ID="rptArticles" DataSourceID="dsLates...