sql-server

"Model already has an element" errors (TSD04105) when using Visual Studio 2008 Database Project GDR2

I am using Visual Studio 2008 Database Project GDR2 to manage multiple databases and I am getting a number of errors related to synonyms. Project-A has a reference to Project-B because Project-A has a number of synonyms to tables in Project-B. The full error I'm getting is "TSD04105: The model already has an element that has the same...

SQL Query for Date Range, multiple start/end times

A table exists in Microsoft SQL Server with record ID, Start Date, End Date and Quantity. The idea is that for each record, the quantity/total days in range = daily quantity. Given that a table containing all possible dates exists, how can I generate a result set in SQL Server to look like the following example? EX: RecordID | Start ...

How can I select and iterate through multiple rows from the database in C#?

I want to select many rows from my SQL Server database and combine them in a certain manner. Currently, I've been using the following method to get these rows: SqlDataSource mySource = new SqlDataSource("ConnectionString","SelectStatement"); IEnumerable myEnum = mySource.Select(DataSourceSelectArguments.Empty); IEnumerator myCount = my...

Need a the last records of a day, from a range of days.

Ok heres the problem, I have 5 different tables created by god knows who each with different data, an dI need to merge them in a single table. My first problem is that each day have a time stamp but I only need the last records add each day, so how can I search each day for the last records and save them on a new table, most of this tab...

Using Stored Procedures as the Business Logic Layer

The company I'm working for is currently using Stored Procedures (in the MsSQL server backend) as their Business Logic Layer. The actual Business Logic DLL just calls the sProcs and basically manages the UI (events, data binding, etc.) I think there's something wrong in the setup, although I'm not sure how to explain it to my colleagues...

How to build a DB based ruleset for web app achievement system?

I'm planning an achievement system for an ASP.NET MVC site. I want the achievement "rules" be stored in a database - to be easier to add new achievements and a central place to manage existing rules. Users will have no access to change the rules. When a user performs an action that could potentially earn an achievement, the db rules wil...

Unique Constraint vs Unique Index

I’m interested in learning which technique developers prefer to use to enforce uniqueness in SQL Server: UNIQUE CONSTRAINT or UNIQUE INDEX. Given that there is little difference in the physical implementation of each, how do you decide which is best? Are there reasons other than performance to evaluate the best solution? Are there da...

Backup Database and push to TFS server

Is that a way that i can schedule to run a SQL agent job to generate the database schema and data script file and then check in to the Team Foundation Server? ...

Changing SQL Server collation to case insensitive from case sensitive?

I've recently installed SQL Server 2008 and I selected collation as case sensitive. I want to make it case insensitive for the entire instance (not for a database in that instance). If I change the collation does it affect any existing databases? if so in what way? ...

Converting MySQL DDL to SQL Server DDL

I have a model that was generated for MySQL 5 but now I need to create these tables on a SQL Server installation. It's been years since I mucked with SQL server and I want to make sure I can convert this script to be compatible. I don't really know what to look for TBQH, so without further ado, here's my MySQL DDL CREATE SCHEMA IF NOT...

inserting a floating point value with a culture where comma (,) is used for "floating point"

I have something like this: foo { a = 1, b = 2, c = 98,3 } I generate the insert query dynamically so end up with this: insert foos(a,b,c) (1, 2, 98,3) anybody knows how to workaround this ? ...

Calculate time difference (only working hours) in minutes between two dates

I need to calculate the number of "active minutes" for an event within a database. The start-time is well known. The complication is that these active minutes should only be counted during a working day - Monday-Friday 9am-6.30pm, excluding weekends and (known) list of holiday days The start or "current" time may be outside working ho...

Database backup in SQL Server 2008

How can i check with SQL query whether Database backup JOB is created or not ? Thank You ...

how to tell in which column the search string was found?

is it possible to tell in which column the search string was found, without having to do it with ifs? if <searchstring> in column1 -- do some stuff here else if <searchstring> in column2 ... ... i won't post the exact query, as it is too cryptical and too long, but here's a query which does basically the same select title...

ValidateExternalMetadata property, what exactly does this do?

I have a package which reads data from a table and based on a column value stores the records in two other tables. Package uses Transaction required property. It was running smooth until recently when I created a non-clustered index on source table to improve performance. The package denies to proceed execution after showing the Progress...

Auto generating column value with respect to another column

Hi, In my application when i insert data i have to generate sequential value for a particular column basing on value in other column. Is there any property which i could set in SQL Server 2005. I am explaining my requirement in more detail: I have table with two fields id and branchid, i have to insert sequential value for branchid a...

replace null values in sql pivot

I have the following query : SELECT * FROM Table1 PIVOT ( SUM(Value) FOR [Period] IN ([06/1/2007],[07/1/2007]) ) AS p Some of the rows returned are null but i want to replace them with 0. I've tried SUM(ISNULL(Value,0)) as Val but it's not working. ( it's saying incorrect syntax) ...

Scalable freetext & parametric searching (C#)

Hey, Currently, we've got an application that needs to perform very fast searches on ~2 mill records. Searches need to search both a large free-text field, and a number of integer/decimal fields between different ranges, along with various functions/computations & sorting. Currently, we're handling this with a big MSSQL database, usin...

Sql Server batch insert takes 10s, problem?

Hi, I have a large batch insert using SubSonic which takes about 10s (sometimes more), will this produce any problems if my website tries to open another connection to my sql server? This batch won't happend that often, but I guess it will happend at the same time as an other connection at some point. And a related question: How man...

Best primary key format for large table

I'm developing an asp.net application that has some potentially large data tables. I would like to know what would be the best way to define a primary key. I know this has been asked before, but since this is for a specific situation, I think the question is valid. I'm using Entity Framework 4 on a SQL server 2008 database. What are th...