sql-server

Optimizing Query With Subselect

I'm trying to generate a sales reports which lists each product + total sales in a given month. Its a little tricky because the prices of products can change throughout the month. For example: Between Jan-01 and Jan-15, my company sells 50 Widgets at a cost of $10 each Between Jan-15 and Jan-31, my company sells 50 more Widgets at a co...

SQL server DB restored.Login failed error

Dear TEchies, I have restored one db back up to my SQL server. I have an ASP program which is accessing the db.When i am running this ,i am getting an error login failed for this user.What exactly i have to do for this ?? ...

Firebird to SQL Server Migration.

Is there a tool native to SQL Server to do the migration (i.e., Import/Export)? Any other options (SSIS). Please point me to helpful info. ...

SQL Group By Year, Month, Week, Day, Hour SQL vs Procedural Performance

I need to write a query that will group a large number of records by periods of time from Year to Hour. My initial approach has been to decide the periods procedurally in C#, iterate through each and run the SQL to get the data for that period, building up the dataset as I go. SELECT Sum(someValues) FROM table1 WHERE deliveryDate BETWE...

Split a varbinary in a SELECT

Hi, I have a large varbinary field in one of my tables, and I would like to download in parts for show a download progress indicator in my application. How can I split the data sent in a SELECT query? Thanks ...

Script for pushing database change to servers

Hi This is probably the most classic database problem. I have an E-commerce software solution hosted on a SQL server for data, and a web server for the frontend. Every instance/customer has its own database on SQL Server 2008. During development of the next version, I might change or add tables, views, stored procedures etc. How do I...

How can I list all foreign keys referencing a given table in SQL Server 2005?

I need to remove a highly referenced table in a SQL Server database. How can I get a list of all the foreign key constraints I will need to remove in order to drop the table? (SQL answers preferable over clicking about in the GUI of the management studio.) Thanks in advance. ...

Server Explorer unavailable (VS2008Pro)

I recently had some problems with my VS 2008, and was recommended to reinstall. To make sure that the reinstall would solve my problems, i manually uninstalled everything that could have to do with VS and SQL Server (I had the 2008 Express edition installed). Now when I reinstall SQL Server and Visual Studio, the Server Explorer in VS i...

Storing Database-Agnostic Schema

We have a set of applications that work with multiple database engines including Sql Server and Access. The schemas for each are maintained separately and are not stored in text form making source control difficult. We are interested in moving to a system where the schema is stored in some text-based format (such as XML or YAML) with d...

Why is this query returning unwanted results?

Good morning, I have a problem with this query: SELECT P.txt_nome AS Pergunta, IP.nome AS Resposta, COUNT(*) AS Qtd FROM tb_resposta_formulario RF INNER JOIN formularios F ON F.id_formulario = RF.id_formulario INNER JOIN tb_pergunta P ON P.id_pergunta = RF.id_pergunta ...

How to execute inserts and updates outside a transaction in T-SQL

Hi, I have stored procedures in SQL Server T-SQL that are called from .NET within a transaction scope. Within my stored procedure, I am doing some logging to some auditing tables. I insert a row into the auditing table, and then later on in the transaction fill it up with more information by means of an update. What I am finding, is t...

Query hangs with INNER JOIN on datetime field

Hi everybody! We've got a weird problem with joining tables from SQL Server 2005 and MS Access 2003. There's a big table on the server and a rather small table locally in Access. The tables are joined via 3 fields, one of them a datetime field (containing a day; idea is to fetch additional data (daily) from the big server table to add ...

How can I automate the "generate scripts" task in SQL Server Management Studio 2008 ?

I'd like to automate the script generation in SQL Server Management Studio 2008. Right now what I do is : Right click on my database, Tasks, "Generate Scripts..." manually select all the export options I need, and hit select all on the "select object" tab Select the export folder Eventually hit the "Finish" button Is there a way to ...

How do you handle software upgrades like SQL Server 2008?

I'm only asking this because I'm finding as I get older, it becomes a much more frustrating part of my job. How do you handle new versions of software, particularly software that coders and DBAs use on a regular basis? It seems that just when I've fleshed out SQL2005, SQL2008 will have come and gone and SQL2010 will be here. I've mi...

What benefits are there for Microsoft Certified Master on SQL Server?

The requirements to obtain a Microsoft Certified Master certification on SQL Server is more extensive than it is to obtain lower level certifications. Aside from the $20k cost (if you include travel expenses), it requires a 3-week immersion period at Microsoft Campus. My question is, in addition certifying a superior experience and skil...

Is there a bug in SqlDataReader.HasRows when running against SQL Server 2008?

Take a look at these two queries: -- #1 SELECT * FROM my_table WHERE CONTAINS(my_column, 'monkey') -- #2 SELECT * FROM my_table WHERE CONTAINS(my_column, 'a OR monkey') -- "a" is a noise word Query #1 returns 20 rows when I run it in Management Studio. Query #2 returns the same 20 rows, but I also see the following in the Messages t...

Creating stored procedure in another database

Any idea if it's possible to create a procedure in another database using T-SQL alone, where the name of the database is not known up front and has to be read from a table? Kind of like this example: Use [MasterDatabase] Declare @FirstDatabase nvarchar(100) Select Top 1 @FirstDatabase=[ChildDatabase] From [ChildDatabases] Declare @SQL n...

Sql Server x64 and x86 Linked Server

I have a Visual FoxPro table that I need to access from Sql Server. In Sql Server x86, I would just create a linked server. Unfortunately, there is no x64 driver for VFP - so Sql Server x64 can't create a linked server to it. So far, I've come up with following options - none of which I'm particularly fond of: Set up an x86 Sql Server...

SQL Reporting Services 2005 - Non-queried Report Parameters

I'm working on a report in Reporting Services and I can't figure out why I'm having trouble with Non-queried report parameters. I'm trying to get the current year and have tried: =YEAR(TODAY()) =DATEPART("yyyy",TODAY()) I have also tried TODAY instead of TODAY() All of these seem to break the Year dropdown on my report. I ...

Swapping the 2 rows in MS SQL server retaining the original primary key and without manual update

I have the following problem : I have rows like ID CODE NAME ......... 1 h1100h1 Cool example1 ......... 2 h654441 Another cool1 ......... I would like to swap them retaining all old primary keys and constraints. Of course, I can easily solve this manually by updating the rows. I am kind of wondering whet...