sql-server-2005

ODS query from Excel returns spurious column names

Hello all When retriving Excel sheet Named region it returns spurious column names OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "No value given for one or more required parameters.". Msg 7320, Level 16, State 2, Line 1 Cannot execute the query "SELECT `Tbl1005`.`CUSTOMER` AS `Col1031`,`Tbl1005`...

(SQL Server 2005) Good way to manage a large number of insert statements?

I have a stored procedure that takes a table name and writes out a series of INSERT statements, one for each row in the table. It's being used to provide sample, "real world" data for our test environment. It works well but some of these sample rowsets are 10, 20k records. The stored proc writes them out using the PRINT statement and ...

How to Get Number of Months and Days From Two Dates

I have two tables: AgeMilestones //Represents available timespans Id int Description varchar //(newborn, 1 month old, 2 month old, etc.) NbrMonths int //( 0, 1, 2, etc.) NbrDays int //(0, 1, 2, etc.) Child Id int DateOfBirth DateTime I need to get the AgeMilestones that a given child has currently passed in age. The ...

Whats wrong with this bcp utility?

I am trying to export data into into a text file using bcp utility? I could n't figure out what i am doing wrong here:- Declare @Cmd nvarchar(1000) Declare @Query nvarchar(1000) Declare @Path nvarchar(500) Declare @ServerName nvarchar(500) Declare @UserName nvarchar(50) Declare @Password nvarchar(50) Declare @Delimiter char(1) SET @Pat...

Generate report using SUM

I've got two SQL Server 2005 tables: MainTable and Orders. MainTable: | MainID | Serial | ------------------- | 1 | A00001 | | 2 | B00002 | Orders: | OrderID | MainID | Name | Value | ----------------------------------- | 1 | 2 | John | 100 | | 2 | 2 | Mike | 200 | | 3 | 1 | John | 150 ...

Display filename only in SQL Server 2005 Management Studio tab

How can I just display the filename only in the tab? Currently I'm getting the full path in the tab. ...

how to convert an SQL server 2005 .mdf to SQL server CE .sdf ?

HI , I created a project where it can work with SQL server 2005. Now i want this project to be migrated to SQL server CE 3.5 which will run in low config system ( XP , 500 MHZ and RAM 488) How do i convert my .mdf to .sdf .I used third part tool lik e PrimeWork but when i am trying to load it says not compatible . any help ? ...

Possible Server Improvements?

Hi All, I need an expert insight to my problem. most of my experience is development so i dont have enough grasp regarding server issues or maintenance. Main problem is when traffic is high request to this SQL server times out. there are several applications connecting to this server, some are web some are windows app. i would like to k...

Insert Trigger - Foreign Key Violation - UnCommittable transaction - SQL Server 2005

I am facing an issue in Insert Trigger. I have 2 tables. Whenever I insert into Table 1, I have written a trigger to insert into Table 2. There is a stored procedure to insert in to Table 1 and there is an After Insert Trigger to insert into Table 2. The table 2 has one primary key and one foreign key. When there is a Primary Key const...

Is it possible to force Business Objects 6.5 to create proper ANSI joins?

The SQL that Business Objects generates seems to be stuck in a bygone era for SQL joins -- it insists on using the old Sybase outer-join syntax (*=, etc.), which is illegal in SQL Server 2005 when running at level 90. Is there an option somewhere to make it use modern join syntax (i.e., joining using the JOIN keyword rather than using co...

SQL Case with multiple fields

I have 3 fields that shows a hierachy in my application. The 3 fileds are as follows: rl.Level1 rl.Level2 rl.Level3 I am trying to show only the last level that is populated in my output. Basically this is what I am trying to do. If level3 is null then return level2 but if level2 is also null then return level1 but if level3 is not ...

How Can I Rid off Redundant Values from a Column?

This is the sample output Let me explain what's going on: The query returns all invoices # of every year along with the products that is involved in the invoice. As you see, we have two invoice in 2010...The invoices are 30463 and 30516. The invoice 30463 has 4 products, its shipping price is 105.88. As you see the shipping price is r...

automate a SQL query to run every month

I have a simple SQL query that updates some date fields in a record, on a SQL Express instance. I'd like to have it run automatically every month. What is the best way of accomplishing this in SQL Server 2005 Express using the Management Studio? ...

Performance issues calling stored proc from within a stored proc

Hello, I worked on a project that had the following requirement: TableA is the parent table. Whenever any children records of TableA are updated the 'LastActivityDate' field in TableA should be updated with the current UTC date. Now, I know there are many ways of doing this. My post is NOT about the many different ways this coul...

Violation of UNIQUE KEY constraint on INSERT WHERE COUNT(*) = 0 on SQL Server 2005

I'm inserting into a SQL database from multiple processes. It's likely that the processes will sometimes try to insert duplicate data into the table. I've tried to write the query in a way that will handle the duplicates but I still get: System.Data.SqlClient.SqlException: Violation of UNIQUE KEY constraint 'UK1_MyTable'. Cannot insert ...

Subtracting count of rows in subquery from current query

In SQL Server 2005, given the following resultset ID | InstanceNumber | IsArchived 5000 | 1 | True 8347 | 2 | True 9343 | 3 | False 11048 | 4 | False What I would like to return is this: ID | InstanceNumber | IsArchiv...

Determine how to calculate split weeks in SQL Server

Im not quite sure what the term is, I have been calling it "Split Weeks" but here is what I need to find out. Given: User will input @StartDate and @EndDate col_week_end_date will always end on a Saturday, and is a DateTime column. I want to cycle through either multiple or a single month(s) and sum col_payment_amt Using the month o...

Cannot open database "gainpeace" requested by the login. The login failed. Login failed for user 'MALIK\ASPNET'.

I'm using this for connection to SQL Server 2005 [Windows authentication] <add key="ConnectionString" value="Data Source=MALIK\sqlexpress;Initial Catalog=gainpeace;Integrated Security=SSPI"></add> but it generates an error Cannot open database "gainpeace" requested by the login. The login failed. Login failed for user 'MALIK...

How to use transactions (begin transaction, commit transaction)?

I have seen transaction usage in some cases but never really understood in which situations they should be used. How and when transactions should be used (begin transaction statement)? I have read that Microsoft do not suggest to use transaction statements (commit, rollback) inside a trigger and stored procedure. ...

Should I use sp_executesql or EXEC to run a stored procedure?

I have a stored procedure that needs to call a 2nd SP multiple times. The only thing that changes are the parameters to the 2nd SP. Something like this: SELECT @P1=5, @P2=5 EXEC MyProc @P1, @P2 SELECT @P1=0, @P2=1 EXEC MyProc @P1, @P2 Now if it was dynamic SQL I was running I know sp_executesql would be better than EXEC but since...