Archived Months
January 2003
March 2003
April 2003
May 2003
June 2003
July 2003
August 2003
September 2003
October 2003
November 2003
December 2003
January 2004
February 2004
March 2004
April 2004
May 2004
June 2004
July 2004
August 2004
September 2004
October 2004
November 2004
December 2004
January 2005
February 2005
March 2005
April 2005
May 2005
June 2005
July 2005
August 2005
September 2005
October 2005
November 2005
December 2005
January 2006
February 2006
March 2006
April 2006
May 2006
June 2006
July 2006
August 2006
September 2006
October 2006
November 2006
December 2006
January 2007
February 2007
March 2007
April 2007
May 2007
June 2007
July 2007
August 2007
September 2007
October 2007
November 2007
April 2008
all groups > sql server programming > october 2004 > threads for tuesday october 26

Filter by Day: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

SELECT Statement that skips first row
Posted by JB at 10/26/2004 11:53:08 PM
I am looking for a way to select the top 5 rows in a table (based on date), however, I want to skip the first row. The query "SELECT TOP 5 * FROM News ORDER BY CreateDate DESC" would give me the top five, but I don't want the first row in that query. The best way to describe this is to use...more >>


Error in Data Conversion
Posted by Luqman at 10/26/2004 11:30:49 PM
I am trying to transfer data from Visual Foxpro Table Version 7.0 to Sql Server 2000 through Sql Server Query:- Insert into mySqlTable Select DCode,PurDate,Amount from OpenDataSource('VFPOLEDB.1','Data Source=D:\FAST-DTML;')...DC_DASET But following Error occured. OLE DB provider '...more >>

Modeling the TV Guide
Posted by Rich R at 10/26/2004 10:17:07 PM
As a data modeler and a trainer I always try to pick a domain that all my students can relate to. So I thought "The TV Guide" ! Let's model the TV Guide using ORM or ERD. Most students choose ORM because of the automatic normalzation. But try verbalizing the TV Guide. Gets non-trivial real fast....more >>

If statement in View
Posted by Gerald S at 10/26/2004 9:31:41 PM
Hello, I am trying to limit the data user access through views, and I need to display different data dependent on their user name: CREATE VIEW dbo.testv1 AS if (select user_name()) like '%-%' begin select * from customers where custid > 1000 end else begin select * from custome...more >>

How to carry forward a balance or last known value
Posted by karenmiddleol NO[at]SPAM yahoo.com at 10/26/2004 8:39:02 PM
I have the following incoming data file with the following structure: Material Year Month Stock on Hand ------------------------------------------------------------------------------- 000000000103063768 2004 03 2.0 000000000103063768 2004 ...more >>

EXEC in stored procedure
Posted by Magnus Blomberg at 10/26/2004 7:12:30 PM
Hello! I'm trying to use EXEC ('SELECT * FROM Categories') into a Stored Procedure, but the users get permission denied on object 'Categories' If I'm using SELECT * FROM Categories everything works. The user haven't any permission of Categories, but the SP should have it. Is the E...more >>

Custom sync between table
Posted by Guy Brom at 10/26/2004 7:08:32 PM
Hi all, I have an old table (named Old) and a new table (named New) For every record in Old where (Old.newkey IS NULL) I want to perform the following: 1) replicate the entire row into New 2) retrieve the @@IDENTITY (after insert to New) 3) update this identity value inside Old.newkey I...more >>

Help with a join query
Posted by flybalz78 NO[at]SPAM yahoo.com at 10/26/2004 6:56:52 PM
Hi, I'm having trouble getting the results I need from a query. I have two tables - Customers and Orders. I need to get a list of customers in California that have placed at least one order, but none in the last 12 months, and also the date of the last order that they placed. Here are the mai...more >>



help on query
Posted by Jen at 10/26/2004 5:49:06 PM
rHi, I have product table with column product id and other single atrribute for this product , also I have schedule table, each product has mutiple schedules, also I have customation table, each product has multiple customations. I would like to have a query that give me the information abou...more >>

page levels
Posted by J T at 10/26/2004 5:33:34 PM
What are page levels? how do we determine how many levels are there ? Thanks ...more >>

Update Trigger Fires Twice
Posted by Stefan Wrobel at 10/26/2004 5:19:02 PM
I'm trying to implement something simple in SQL Server and the results are driving me nuts. I have two tables, one that stores current information and one that is an audit trail of anything deleted or updated in the current table. For example, if I have a row in current and it is updated, I ...more >>

Select statement
Posted by Steven Richardson at 10/26/2004 5:03:07 PM
Anyone know how two join muliple records into 1. I have 3 tables like the Pubs DB. Authors Titles TitleAuthors This allows for many to many relationships. I need to be able to query this database so I can import titles & authors to a system that does not deal with many to many relatio...more >>

Query with MIN?
Posted by Ron Hinds at 10/26/2004 4:37:31 PM
The following table contains vendor quote information. There can be several vendors for any given part number, with differing values in the quoEstimatedCost column. How would I write a query to extract the quoVendorID that has the lowest quoEstimatedCost for every part number (the results will b...more >>

how to "EXEC c:\abc.sql" in Enterprise Manager ?
Posted by SOHO at 10/26/2004 4:32:13 PM
-- Thanks ! ...more >>

Return length of the value (after the decimal places)
Posted by Chris at 10/26/2004 4:29:01 PM
I've declared a field called costpernight as a money. I now want to run a query which will return the len of the value after the decimal places. For example:- 123.45 should return 2 123.456 should return 3 12345.67 should return 2 12345.6789 should return 4 What is the best way to ret...more >>

Cursor vs. set-based normalization
Posted by Mark Wilden at 10/26/2004 3:53:37 PM
I like to be a "good" SQL programmer and use set-based solutions where possible (because I recognize they are usually faster than cursor-based solutions), but I'm wondering if I'm barking into the wind trying to come up with a set-based solution to this problem, when the cursor-based solution is ...more >>

Database Activity
Posted by Patrick at 10/26/2004 3:29:56 PM
Hi Freinds, I get responsibility to clean up 10 SQL servers, where each one has 20-30 databases My question is that how can I find out the activity on each database. I want to start from those which are dead databases. Thanks in advance, Pat ...more >>

Run a SP when server restarted
Posted by Patrick at 10/26/2004 3:20:58 PM
Hi Friends, I need to run a SP ( which is the profiler and records the SQL server) when ever the server or better to say SQL server agent restarted. Where and how should I do that? Thanks in advance, Pat ...more >>

How to Export all data of a table into an excel file by a SQL statement?
Posted by RC at 10/26/2004 3:16:39 PM
Question as title. Thanks. ...more >>

I am having a problem combining Two SQL queries. Please Help
Posted by Ian at 10/26/2004 3:11:58 PM
Hi all I have these two queries. ONE SELECT tbl_BTP_Scenario.ScenarioID, tbl_BTP_Scenario.ScenarioOrder, tbl_BTP_Scenario.ScenarioName, tbl_BTP_Scenario.ScenarioDescription FROM tbl_BTP_Scenario Where tbl_BTP_Scenario.BTP_ID = 19 ORDER BY tbl_BTP_Scenario.ScenarioOrder TWO SELECT ...more >>

Extract PK's
Posted by Joe Horton at 10/26/2004 3:01:31 PM
Looking for a query that will return all PK's for all tables in a DB. What I really am trying to do is build a drop script for just the PK's....more >>

Internationalizing
Posted by Jon at 10/26/2004 3:01:00 PM
I have a large database of approximately 120 stored procedures and a couple hundred tables. I am in the planning stages of internationalizing our product. I understand that I need to change all text and varchar, etc to nvarchar, etc. I can visualize in my mind code needed to loop through ...more >>

Deleting SQL Server Registration
Posted by Lontae Jones at 10/26/2004 2:21:04 PM
I am trying to set up replication and my server is registered as local and to configure replication it is telling me to delete the registration and re-register it using the server name. My question is will this affect any databases? Is this ok for a production system....more >>

Converting binary data to text
Posted by Peter Strøiman at 10/26/2004 2:07:23 PM
Hi. I have a table with a poorly chosen definition. (Well it's my own fault - but anyway!!) There is an image field, but there is only stored text in it. Now I need to create script to change the database structure, and I want to convert it to text but I can't. I tried experimenting and ...more >>

Views or Complex Queries
Posted by Ed at 10/26/2004 1:19:04 PM
Hi, I am working on one of the database which has about 100 views. The reason is because some views are based on other views. I am wondering if it is a good idea to put some views into one complex views to reduce the number of views. But what I concern about is some users/developers ...more >>

Date-Comparison Query - Please Help
Posted by betenoire NO[at]SPAM betenoire.net at 10/26/2004 12:56:29 PM
Hi all, I have 3 dates in a table, and I want to return the only most recent date of the three for each row. For example, if I have the following 4 columns in a table... RowID (smallint) Date1 (smalldatetime) Date2 (smalldatetime) Date3 (smalldatetime) ....how do I contruct a SELECT ...more >>

Datetime Format
Posted by Harikumar G at 10/26/2004 12:36:34 PM
Friends, My hardware sends me a date format like this 15:10:20.99 UTC Mon Oct 18 2004 I need to process this format and parse to a valid SQL datetime format, how can I do it more easily? My front-end language is C# -Hari ...more >>

Copying a table
Posted by Kevin at 10/26/2004 12:09:02 PM
I am using asp.net and sql 2000. In my program I am doing a lot of data manipulations and before I do this I would like to copy my table to another table, just in case I need to put the data back to its original state. I would like to do this in the asp.net program. Can anyone help? Thank...more >>

SQL syntax - Conver from char to int data type error
Posted by Bill Nguyen at 10/26/2004 12:08:24 PM
update if_stationterritory set territoryid = (select fleetpoint from if_owa1 where cast(substring(ltrim(if_sitecode),1,4) as int) = stationid) stationid is integer if_sitecode is char(20) error message: Server: Msg 245, Level 16, State 1, Line 3 Syntax error converting the varchar value ...more >>

Preserving a primary key when moving a table to a different database
Posted by Carl Imthurn at 10/26/2004 12:00:08 PM
Hi folks -- Simple question, but obviously beyond me. How do you preserve the primary key of a table when moving it from one database to another? First attempt -- DTS. No luck. When I checked the table in the destination database, the primary key was gone. Second attempt -- SELECT * ...more >>

Query to get snapshots of history
Posted by Matt D at 10/26/2004 11:50:27 AM
The design of my database is such that only the stored procedures are aware of the implementation of the database and it's individual tables. The client program that calls these stored procedures only sees one table that is the result of the many joins that are done. An example of this using the...more >>

How to avoid cursor/loop on inserting into multiple tables
Posted by Eric Tishkoff at 10/26/2004 11:35:01 AM
I frequently need to update several interdependent tables at once and would like to find a set-based solution. Is there a way to do this sort of operation without a loop or cursor? Thanks, Eric -- EXAMPLE CREATE TABLE [dbo].[a] ( [aId] [int] IDENTITY (1, 1) NOT NULL , [val] [varch...more >>

Need an option setting
Posted by Rizwan at 10/26/2004 11:25:10 AM
i have a SQL Server 2000 database. I have created a table USER an insert some data in it. When I try to run the query select * from user in query anlayzer, I got his error message : Server: Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'user'. it only works if i chan...more >>

openquery syntax
Posted by matt NO[at]SPAM throttlenet.com at 10/26/2004 11:24:19 AM
I have two seperate databases with the same table names but different columns. The databases are linked together. Below is an example of what I'm working with starting with the database names and underneath the different columns which will need to match each other. Sales Database : orders(t...more >>

Using Local Variables in a View
Posted by Raul at 10/26/2004 11:01:07 AM
I'd like to use some local variables in a view, but SQL Server doesn't seem to like declare statements or set statements in views. Query analyzer doesn't seem to mind the query and the same query works as a stored procedure. Am I missing something? Thanks, Raul...more >>

kill not working
Posted by Ned at 10/26/2004 10:47:02 AM
Hi, We are having a lot of problems when killing a spid. The spid stays in the rollback/killed mode and holds its locks until we shutdown the engine. When trying to kill it again we always get SPID 62: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time ...more >>

Permissions on a SP
Posted by Jaygo at 10/26/2004 10:26:10 AM
I have created and tested two triggers directly on the local server and both work as they should. I initially had a problem with xp_smtp_sendmail that was returning a 500.1 Internal server permissions error, I corrected this with applying the correct permissions. Both triggers work when acti...more >>

How to pass variable to a USE [@mDBName] statement?
Posted by Marco Napoli at 10/26/2004 10:17:56 AM
I have tried the following code in order to pass a variable to the USE [@DBName] but it gives errors that it does not reconize the @DBName variable, it things the @DBName is the actual database name. DECLARE @DBName VarChar(254) SET @DBName= 'MyDB' USE [@DBName] Thank you Peace in...more >>

Custom COM resolver using .NET
Posted by Darren at 10/26/2004 10:05:28 AM
I've been trying to write a custom replication resolver in C# but I don't seem to have all the pieces. When I use regasm.exe to register the resolver shows up when I use sp_enumcustomresolvers. When a conflict occurs I get an error message "The process could not initialize 'My Custom Resolver' ...more >>

help optimize my query
Posted by JT at 10/26/2004 9:39:55 AM
just wondering what is the better way of doing this query - basically i need to sum 4 different amounts based on the account_id --use a case statement SELECT @mySum32 = IsNull(SUM(CASE account_id WHEN 32 THEN amount ELSE 0 END), 0), @mySum28 = IsNull(SUM(CASE account_id WHEN 28 THEN am...more >>

help with query please!!! max() and joins
Posted by Joe Scalise at 10/26/2004 9:35:03 AM
I have a clients table, a payment receipt table and a payment promises table. I need to select all clients that have a late payment, this would mean selecting the most recent payment receipt date, max(receiptdate), making sure they don't have a recent payment promise, max(paymentpromise) an...more >>

cancelling a query in an application
Posted by Bob at 10/26/2004 9:29:39 AM
Strictly speaking this is a question for the vb.net NG, but I've had no luck there and thought I'd ask here: I want to provide a query cancel feature to a WinForms applilcation. What is the best method is for doing this when you take any server-side effects into consideration? I want to do it the...more >>

kill not working
Posted by Ned at 10/26/2004 9:29:03 AM
Hi, When trying to kill a process the process never seems to die. When executing the kill command again we get this message: SPID 62: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time remaining: 0 seconds. which hangs around for hours. We eventually h...more >>

Creating an automatic date variable
Posted by Raul at 10/26/2004 8:59:06 AM
I need to create a start date for a query and the date range needs to be the past 24 months. To make things a little more complex I need the start date to be the first day of the current month with the year being two years prior to the current year. The following methodology works but I'm su...more >>

Loop though select statement
Posted by j1c at 10/26/2004 8:36:54 AM
Can I loop through a select statement with t-sql, grab a value at a time and then use it in a stored procedure? ...more >>

VARCHAR data type - TEXT data type
Posted by THM at 10/26/2004 7:59:23 AM
Hello I have a table that one of its colunm is TEXT data type (very big length characters). When I try to use (by selecting) the TEXT in database procedure I get the next error: "The text, ntext, and image data types are invalid for local variables." My procedure: .. declare @idoc int ,@...more >>

ORA-00903 Invalid table name
Posted by bertholomaeus NO[at]SPAM yahoo.ca at 10/26/2004 7:09:49 AM
Hi all, I receive the above mentioned error message for an easy select: select SYDATE from dual We use Excel 2000-SP3 thx bert...more >>

What stored procedures call this stored procedure?
Posted by Joe Palm at 10/26/2004 6:57:06 AM
Given a stored procedure written by us, how can we get a list of what other stored procedures in the same database call it? -- Joe Palm Senior Technical Developer Madison, WI...more >>

When is a clustered index appropriate?
Posted by Novice at 10/26/2004 6:19:02 AM
Hey all, I'm just going through my data model for a database I created and trying to ensure that it is optimized for the types of queries I'm going to be running against it. But even after reading about 10 articles I'm still not 100% certain of when to apply a clustered index, or an unclust...more >>

Backup file or files group with differential
Posted by hilaire.verschuere NO[at]SPAM netcourrier.com at 10/26/2004 5:40:47 AM
Hi everybody, Does anyone knows if it has an interest to perform a backup of a file or a files group in differential mode ? In fact when I perform a full backup or a differential backup on a file or a files group, both backup has the same size, so I don't see the interest of differential ba...more >>

Question on sp_databases
Posted by Wayne Wengert at 10/26/2004 5:35:06 AM
When I execute sp_databases and bind the results to a datagrid I get three fields returned: "Database_Name", "Database_Size", and "REMARKS". The remarks field is always (null). Where/How can the value of that REMARKS field be set? Wayne ...more >>

osql aggregate outputfil
Posted by CJ at 10/26/2004 2:29:02 AM
Is it possible to run a lot of OSQL statement and write to the same outout fil?...more >>

please help
Posted by kalikoi NO[at]SPAM yahoo.com at 10/26/2004 2:25:52 AM
Hi everbody, anyone can help me? when i type select * from table1 then i get the following ----------------------------------------------------- Ticker col2 col3 col4 col5 ---------------------------------------------------- BRK.A 2003-05-02 70400.00 0.00 78500.00 FARM 2003...more >>

strange sp problem
Posted by Henok Girma at 10/26/2004 1:23:45 AM
Hello Gurus, I have a very disturbing problem. I have the following very simplified version of the table.. Equipments Client_ID int, Store_ID varchar(30) . . . some other fields I have a stored procedure to add data to this table declared as follow spEquipAdd (...more >>

Week function
Posted by Stanley at 10/26/2004 1:15:06 AM
Hi, i would like to have the weeknumber of a certaindate. myDate -------------- 2004-01-01 2004-01-02 ..... 2004-12-31 So i use: WEEK(myDate) But the week function prsumes that a week starts on sunday, but i would have it to start on monday. How can i tell the function that it...more >>

Query of Cummulative Values
Posted by Tim M at 10/26/2004 1:11:04 AM
Hi, How do I create a query that will return a set of records where a particular field value is the sum of values for all previous records in the recordset. eg I have a table that holds values like Month Cost ------- ------- 1 1000 2 500 3 1000 4 ...more >>

In a stored Proc. how to access two databases?
Posted by Andreas Klemt at 10/26/2004 12:56:28 AM
Hello, I have a stored procedure and I want to access tables in different databases like this: DECLARE @test int DECLARE @test2 int SELECT @test=test FROM dbo.database1.mytable SELECT @test2=test FROM dbo.database2.mytable This is not possible. I get an error message. How can I...more >>


DevelopmentNow Blog