sql-server

Should I add this new column to customers table or to a separate new table?

Hello, I have a customers table with information about our customers (ID, login, name, contacts info, different options, TS column, and so on, ~15 columns, ~few hundreds of customers). Now we need to send every-day-updates to our biggest customers (<10% of all customers). And I need to store timestamp of the latest update which were s...

Modeling an organizations hierarchy then been able to map details of each different organization in Nhibernate

We are trying to model a school system hierarchy from State>County>District>School, hence we are using the model below to describe the parent child relationship along with organization type (i.e. School, District,…). Organization Hierarchy Now we need to store details on each particular organization, for example if it’s a school we n...

What should I keep in mind if I wish to merge many DBs into one DB?

I am working with a half dozen DBs. The DBs all have the same schemas, the same SPs, etc. Speaking to the person who originally designed the DBs, a big part of the motivation for using many DBs was efficiency; the alternative would be to add a column to pretty much every table and sp in the database indicating which set of data was bei...

SQL Server - selecting data where not exists

I need a way to be able to select from a table if that table doesn't contain data of a certain type. For example if we have a table called farm and another table called animal. Now FarmA contains a pig and a goat and FarmB just contains a goat. I want to select all farms that contain no pigs. My first try was to do this: SELECT f.* F...

Re-usable SQL Server stored procedures; nesting; global variables

I want to make some re-useable, somewhat-dynamic TSQL code that can be called within many other stored procs, but I'm struggling with how to implement this with SQL Server. The environment is that many distributed source systems databases which will have their own wrapper stored procedure which will call a few of these modular stored pr...

Is there a way to "export" an entire SQL Server database (schema and data) to text?

On a per-object basis, SQL Server Management Studio has the option to script the object to clipboard, file, etc. Is there a way (at the database level) to do a "1-click" export of ddl AND data to a text file? Ideally I'd like to select a database and create a big text file containing the ddl for all objects plus the data in all tables....

Search and replace content in stored procedures

I realy dont know how I could have lifed without searching the text of stored procedures http://stackoverflow.com/questions/466130/can-you-search-sql-server-2005-stored-procedure-content. The next big think for me would be the ability to replace some text in a couple of stored procedures. Is there a way to do this? ...

Better way to write a Query with 4 possible paths?

May not have been the best title but anyways.. I have a stored procedure which until now had 1 optional parameter which I easily solved with 1 if statement. Now it has 2 which brings it up to 4 if statements. I would like to know if there is a better way to write a query then the following. Especially if/when a variable count goes up to...

What is the escape character for SSIS Expression Builder?

I need to escape quotation marks in SQL Server Integration Services' Expression Builder. I cannot escape it with double or triple quotes. ...

Crystal Reports 9 and Sql Server Synonyms??

We use a variety of Schemas in our SQL Server 2005 installations. Crystal Reports works with those properly but I have a third party app that won't render the Crystal Reports that use different Schemas (no clue why). Is it possible to get Crystal to recognize a table that is addressed by a Synonym? If so how? ...

Making MEDIAN a function like AVG in SQL server

Hello, I am new to SQL server. I need to calculate the median of the time stamp values in my table, Table1: _TimeStamp 2009-12-20 11:59:56.0 2009-12-20 11:59:56.5 2009-12-20 11:59:56.3 2009-12-20 11:59:56.4 2009-12-20 11:59:56.4 2009-12-20 11:59:56.9 There is a nice solution to calculating medians here, http://stackoverflow.com/que...

Recommend a book on load-testing an ASP.NET application

I need a book to recommend strategies for load-testing an ASP.NET application with SQL Server backend. Some info that may be useful: how to write a load test plan what perfmon counters to use and typical threshold values finding bottlenecks various load testing tools ...

ASP.Net membership + sql server 2008

update: Forgot to mention that the app only breaks and shows that error when I try to login as asp.net membership user (sql membership provider), before that everything is fine and the app communicates with the sql just fine. Hello, I'm writing an asp.net app that's using asp.net sqlmembership and connecting to a SQL Server 2008 datab...

Is performance of DB slow in sql server 2005 express compared to sql server 2005 enterprise ?

Is performance of DB slow in sql server 2005 express compared to sql server 2005 enterprise ? Comparison between sql-server 2005 and express 2005 is here Comparison between sql-server 2008 and express 2008 is here ...

To store and search word documents using C#.NET,ASP.NET

i want to store a word documents (.doc) in the database and i need to provide search over a collection of Word documents and highlight the words too. I m using VS2005 --> ASP.NET, C#.NET, SQL Server. ...

LINQ to SQL datacontext update after changing SQL Server name

In a WPF application I use LINQ to SQL, SQL Server 2008. SQL Server computer was replaced and SQL Server was installed under instance name not the same as before. Database was restored under the same name as before. The new connection string was added to the application. But it appeared that it is impossible for the application to con...

SQL nvarchar considerations

What's your strategy for determining nvarchar column sizes say for a address field? Do you always use nvarchar(max) or a fixed maximum size? There is nothing worse than data integration breaking due to too small columns. What are possible implications of using nvarchar(max) vs. a fixed maximum varchar size? I understand there is somethi...

When to use what functions vs Sprocs

Hi t-sql I tried to read the difference between UDF and sprocs, here http://realfantasy.wordpress.com/2009/01/05/sql-server-user-defined-function-udf-vs-stored-procedure-sp/ Do u know more differences? When to use what? Thanks ...

How to create a query to list all combinations possibilities

Hi I have a currency(Rec_ID, currency) table which is having M-M relationship with it self it results in CurrencyExchangeRate table (Rec_ID, Currency_FK1 AS 'FROM', Currency_FK2 AS 'TO, Exchange_Rate) Now I need a query to do all combination of currency rec_id (repetition is not allowed), along with the exchange rate or null. if there ...

Calculating how many Working Days between 2 Dates - T-SQL?

I realise different solutions will have different variations of what "Working Days" means but in my case I mean Monday to Friday inclusive. Basically I have Created a function to do the calculation for me and my current solution works. My concern (and reason for asking this question) is that I am worried that this is a bad way of achiev...