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 > april 2005 > threads for friday april 8

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

question on failure inside a transaction
Posted by David at 4/8/2005 6:14:08 PM
I want to issue a transaction where whole transaction should roll back properly. I want to be sure that anything that stops these statements from working will rollback the transaction. Example, the table2 no longer exists below so I get error Invalid object name 'table2'. How do I get sql to ...more >>

ANSI's stance on SmallInt vs. Int
Posted by Thomas at 4/8/2005 5:45:22 PM
I decided to push this out to it's own thread. Here's the question, if you are deciding to abide purely by ANSI SQL 92 standards and are only thinking in terms of the logical model, how does the modeler decide when to use a SmallInt vs. an Integer if the allowed range is considered a physical ...more >>

Linked server performance
Posted by Vern Rabe at 4/8/2005 4:37:55 PM
SQL Server 2000 Standard, SP3a. I have a linked server defined pointing to DB2, using their DB2 Connect driver. When I execute a single table query from SQL Server against the DB2 linked server with a highly selective where clause using four part naming, it appears as if the query retrieve...more >>

Query question
Posted by viktor at 4/8/2005 4:13:15 PM
SELECT item_id, unit_price, date_created FROM dbo.p21_view_po_line where complete='Y' GROUP BY item_id, unit_price, date_created OREDR BY item_id I NEED FOR EACH ITEM ID LAST DATE CREATED. ANY HELP PLEASE ...more >>

Creating Scripts via Query Analyzer or Enterprise Manager
Posted by epigram at 4/8/2005 4:04:24 PM
I'm trying to decide what is the best practice in terms of creating scripts that, for instance, update an existing database. It seems there are a couple of ways to do this (although I am sure there are more). It is often suggested that you code your changes, by hand, using Enterprise Manager...more >>

Select Statement Question
Posted by Devin at 4/8/2005 4:03:02 PM
Im running into a problem here and i am unsure if it's possible to do this, and i have the slightest idea on how to do this. This is what i need to do though. I have a select statement SELECT IPQ20101.IPORFQNumber, IPQ20101.IPORFQDate, IPQ20101.EXPDATE, IPQ20101.BUYERID, IPQ20101.L...more >>

Query Question
Posted by viktor at 4/8/2005 3:56:11 PM
SELECT item_id, unit_price, date_created FROM dbo.p21_view_po_line where complete='Y' GROUP BY item_id, unit_price, date_created OREDR BY item_id I NEED FOR EACH ITEM ID LAST DATE CREATED. ANY HELP PLEASE ...more >>

SUM with a UNION
Posted by Darren Woodbrey at 4/8/2005 3:02:33 PM
I need to do the following: select sum(total) from wo_main UNION select sum(total) from wo_main_hist This is great except it outputs2 different sums, one for wo_main and one for wo_main_hist. How can I combine them? Thanks! ...more >>



a msde question (maintenance plan)...
Posted by === Steve L === at 4/8/2005 3:01:43 PM
can one use the maintenance plan to do a scheduled backup job for a msde (sql2k) database? i tried to do it, but there is no schedule availalbe under the complete backup tab. thank you ...more >>

Convert function
Posted by Tory at 4/8/2005 2:46:41 PM
In a query, how do I convert a datetime to display as mm/dd/yy hh:mm AMorPM? I don't see that option on the list of values in Sql Books. The only option I find for including the time abbreviates the month rather than using numericals: Convert(varchar, myDateTime, 9) displays: Jun 17 1998 12:...more >>

sql help
Posted by Arul at 4/8/2005 2:45:03 PM
In the following code, the cursor returns a single column with more than one row. I'm trying to concatenate these rows to show them in a single row separated by comma. The problem is with @degrees. I guess, since this is not initialized, it always returns null. How do I handle this? T...more >>

is there a way to reuse trigger logic?
Posted by jason at 4/8/2005 2:40:36 PM
considering the following example: CREATE TABLE foo (fooid int not null, datecreated datetime) GO CREATE TRIGGER tr_foo ON foo AFTER INSERT AS UPDATE foo SET datecreated = GetDate() WHERE fooid IN (SELECT fooid FROM Inserted) GO if i wanted to do this on every single table, all ...more >>

is there a way to reuse trigger logic?
Posted by jason at 4/8/2005 2:32:29 PM
considering the following example: CREATE TABLE foo (fooid int not null, datecreated datetime) GO CREATE TRIGGER tr_foo ON foo AFTER INSERT AS INSERT INTO foo (datecreated) VALUES (GetDate()) GO if i wanted to do this on every single table, all with the column named [datecreated], i...more >>

xp_cmdshell
Posted by Andre at 4/8/2005 2:27:51 PM
I need to copy a file from another domain to my sql server. Is it possible to somehow pass credentials when I try to do something like this? exec master.dbo.xp_cmdshell 'copy \\172.17.72.202\sharename\filename c:\import\' If not, do you have any suggestions for how I'd accomplish this in an...more >>

Totals and Percentages
Posted by daniel at 4/8/2005 1:50:15 PM
This is probably an easy one but I can't seem to get it. I have the following query: SELECT Category, COUNT(Category) FROM v_test v GROUP BY Category ORDER BY Category DESC but would also like to add one more column to show the percentage total of each category. how do i count the ...more >>

IF statement not executing as expected. Why ?
Posted by salvo at 4/8/2005 1:23:36 PM
Hi, new to TSQL, I'm facing a strange issue with a very simple stored procedure (sic). My procedure checks for @dbname existence. If @dbname exists on server I drop @dbname.Table1 then create a blank Table1. If @dbname doesn't exist I create @dbname, grant access to user1 then create @dbnam...more >>

SQL Bizarreness
Posted by Mike Labosh at 4/8/2005 1:12:54 PM
SQL Server 2000 Standard Edition + SP3: -- This returns no records in Query Analyzer SELECT * FROM SampleSourceArchiveAndProfilingView WHERE (SampleSourceKey = 1650) AND (CompanyLocationKey IS NULL) -- This returns a count of 376981 SELECT COUNT(*) FROM SampleSourceArchiveAndProfilingView...more >>

Dynamically assigning a value using the "Top N" Clause
Posted by T Harris via SQLMonster.com at 4/8/2005 1:05:39 PM
I've developed a proc that takes an input parameter @TopN Int. I want to use it to dynamically pull the top n records from my DB as such Select TOP @TopN UserID, Metric1, Metrics2.... Order By Metric1 I can only get this to work if I use an integer constant. i.e. Select TOP 10 UserID I...more >>

Bit vs. Varchar?
Posted by Drew at 4/8/2005 12:25:19 PM
Saw a friend of mine using a varchar field like a bit field (only storing 1 character). I told him that it would be better to change that to a bit field, and he said, Why? What is the difference between Varchar(1) and Bit? Thanks, Drew ...more >>

Indexing
Posted by Steve Caliendo at 4/8/2005 12:17:12 PM
Hi, Could someone please tell me the "best" way to index a table? Is the best way (defined as quickest access to data) to create an index on every field individually that might be queried, or is it best to create an index that contains multiple fields if that's how they appear after the WHERE...more >>

Query Question
Posted by Shane S at 4/8/2005 12:09:06 PM
I am executing the following query to determine the number of issues closed and opened in a problem tracking system: declare @BeginDate as datetime declare @EndDate as datetime set @BeginDate = '04-01-2005 12:00:00 AM' set @EndDate = '12-31-2005 12:00:00 AM' select [Date], S...more >>

Concatenating in Left Join Query
Posted by hexa at 4/8/2005 11:17:02 AM
I need to create a concatenated field based on both sides of a LEFT OUTER JOIN. When I tried this, I got all nulls in my resultset for that field. What I wanted was whatever is in the left side concatenated with nothing if the right side doesn't exist. How can I achieve this. My current S...more >>

Managing Triggers
Posted by Richard at 4/8/2005 11:15:02 AM
How can I query to see all of the triggers that have been disabled or enabled?? Is there a way to do this using query analyzer or using a gui tool? THanks Richard...more >>

need help writing batch without cursor
Posted by iaesun NO[at]SPAM yahoo.com at 4/8/2005 11:13:45 AM
i'm trying to write a batch that will perform a complex task using set-based selects instead of a row-based cursor. let me know if you can help me figure out how. description of what i'm trying to do: there is TABLE1, TABLE2, and TABLE3 i want to select each row from TABLE1, do some analy...more >>

Rebuildix clutered index on different field
Posted by Igor Marchenko at 4/8/2005 11:04:29 AM
Hello! I have got a table with clustered key defined on primary key. This tables is referenced using FK by hundreds of other tables using its primary key. I am trying to build clustered index on different column in the most efficient way. It looks like I have to drop PK constraint first bef...more >>

Need help with SELECT; DDL included; Revisited
Posted by Terri at 4/8/2005 10:55:40 AM
The solution works great although I am having a little trouble understanding the logic, particularly HAVING MIN(A.accounttype)<MAX(A.accounttype). How would I modify these query to select only those securityIDs that are held exclusively by accounts with a type of A? SOLUTION: SELECT P.sec...more >>

@@identity
Posted by M.Smith at 4/8/2005 10:53:38 AM
I am running an insert sp that looks like this ***************************** @x int, @x1 int, @x2 int, @NewID int AS BEGIN INSERT INTO TABLE1 (x,x1,x2) VALUES (@x,@x1,@x2) SET @New ID = (Select @@IDENTITY) INSERT INTO TABLE2 (@newID,@x) END *********************** I am getting...more >>

Bizare String Concatenation Issue - Explanation Needed
Posted by Mike Treadway at 4/8/2005 10:47:01 AM
Hi all, can someone please explain why this is happening: I execute the following: DECLARE @temp VARCHAR(500) SET @temp = '' SELECT @temp = @temp + '[' + T.NAME + ']' FROM MyTable T SELECT @temp Say [MyTable] looks like this: |NAME| -------- A B C D Here are the res...more >>

Query to Retrieve Latest Row from each group !!!!!
Posted by adam at 4/8/2005 10:15:01 AM
Hi SQL Query Expert, My table looks like this: CONTRACT_PK PARENT_PK CONTRACTOR_NAME CREATED_DATE 1 <NULL> ABC Company 4/7/2005 11:10:10 a.m. 2 1 XYZ Company 4/8/2005 10:10:1...more >>

Bloated SQL Server 2000 database
Posted by dm4714 at 4/8/2005 10:14:23 AM
Hello -- I have a database that is 102GB in size. It has been growing expotentially every month for the past couple of years. Since we have a bunch of similar database, we did not understand why this database was so much larger than the other databases, considering roughly the same kind/am...more >>

Date Value Return Format
Posted by Shane S at 4/8/2005 9:59:08 AM
I am executing the following SQL query to determine the number of entries per date in a table: select entered_date "Entered Date", count(*) "#of SRs" from nxsdfct where defect_status in ('Fixed', 'FIXED', 'Assigned to QA','Hotsite Verified') and prod_code = 'aSU' group by entered_date ord...more >>

Query Question
Posted by tarheels4025 at 4/8/2005 9:57:04 AM
The query belowe does what I want it to do but it only lists stores greater than 0. I would like it to list all the stores regardless if it doesn't have any. I have linked a table with all thew sotres in it so I thought that would work but it doesn't. Anyone have any clues? Thanks. SELE...more >>

ORDER BY changing resulting row count
Posted by Ted O'Connor at 4/8/2005 9:32:34 AM
I have three queries that only differ in their ORDER BY clause but return three different result sets. In the examples below "Takedown" is a table, "CommitID" is an int column, and "TakedownDate" is a datetime column, and neither of these columns have NULL values. select * from Takedown where...more >>

Help with Column Widths
Posted by Rob Gibson at 4/8/2005 9:27:05 AM
How can I find out the sizes of the columns that are returned from a query? I need to know so that I can pad each one to it's full size with spaces so that everything will line up using a mono spaced font in a textbox .NET control. If I fire off a query and get back a DataSet of results, the...more >>

HELP with SQL Query to Retrieve TOP Row from each group !!!!!
Posted by adam at 4/8/2005 9:21:03 AM
Hi SQL Query Guru, My table looks like this: CONTRACT_PK PARENT_PK CONTRACTOR_NAME CREATED_DATE 1 <NULL> ABC Company 4/7/2005 11:10:10 a.m. 2 1 XYZ Company 4/8/2005 10:10:12 ...more >>

Indexing Huge Table
Posted by Amit Patel at 4/8/2005 9:19:03 AM
Well i have a database on my production server which is containing a table having 10 million records and daily 10 - 20 K records are being inserted into the same. The Table is also containing 25 indexes on different columns so which is best time and way to reindex my table for newly inserted ...more >>

Simple query needed - Yes, I'm a newbie to SQL ;)
Posted by AMeador at 4/8/2005 9:15:07 AM
I hope this doesn't get posted twice, I was editing this message a minute ago and I hit something and it went away. I was using a web submission form, so I don't know if I submitted by mistake or killed the submisison. Anyway, I have a table TaskType: TYPEID - int TYPE - varchar(30) S...more >>

17 decimal places
Posted by John at 4/8/2005 8:59:08 AM
Hi, In excel, 0.018/12 give me the following result: 0.00666666666666667 But in query analyzer, select CAST((0.08/12.0) AS real) transaltes to 0.006666. How can I get the same result in query analyzer as I am getting in Excel. TIA...more >>

Datatype of column dynamically
Posted by mahajan.sanjeev NO[at]SPAM gmail.com at 4/8/2005 8:49:31 AM
Hi All, How can I get the datatype of a column using a query? Thanks, Sanjeev ...more >>

Aggregate Strings While Aggregating Data
Posted by Raul at 4/8/2005 8:29:02 AM
I'm using the following query to determine the TotTons produced daily. A sample data set is included. On days that two grades are produced, I'd like the Grade name to be a combination of the two grade names separated by a \. For example the desired Grade name for 08-01-05 would be H\V. A...more >>

Insert Index To Table
Posted by Joe K. at 4/8/2005 8:09:02 AM
I have a database with 50,000,000 rows of data which is approximately 7GB in size. The samples with date time (sampled_time) are in the varchar(24) format. Our select statement use the sampled_time to restrict the data that is retrieve from the database. How can I add index to this tabl...more >>

Getting details for SQL Errors
Posted by mahajan.sanjeev NO[at]SPAM gmail.com at 4/8/2005 8:03:08 AM
Hi, I am writing a program to enable users to import data to SQL Server DB. For this, I build a dynamic query on the fly using the columns (first row in the spreadsheet) and try to insert data into a SQL table. Most of the times it works. The problem happens when there are some data issues ...more >>

Combined Primary Key - Why?
Posted by Naveen at 4/8/2005 7:21:02 AM
In a many to many relationship, say Product to Orders with ProductOrders being the associative entity, what is the most commonly used definition for Primary keys (PK) in the associative entity and why? a)ProductOrders: ProductID - PK, OrderID - PK OR b) ProductOrders: ProductOrderID(PK, mostl...more >>

PLEASE HELP SOON!! SQL Is Not Playing Nice!!
Posted by CSDProgrammers at 4/8/2005 7:07:04 AM
Here is my select statement: SELECT 'INTOL' AS company, pm.newpartnum, '', cast(month(getdate()) AS varchar(2)) + '/' + cast(day(getdate()) AS varchar(2)) + '/' + cast(year(getdate()) AS varchar(4)) AS effectivedate, vend.vendornum, CASE WHE...more >>

SQL Server and Data Integrator
Posted by Mahesh at 4/8/2005 7:03:03 AM
We have developed a application in SQL Server with Data Integrator.. The DI refers xp_cmdshell to call a .net application which takes data from 1 file and generate output in another file.. there are 5 such sequences (A , B , C , D ,E)..which runs one after another... The development environmen...more >>

unique values in a field if different to NULL
Posted by Filippo Bettinaglio at 4/8/2005 6:08:38 AM
Hya, I have a field in a table call PinNo PinNo --------- 123 <null> 343 <null> <null> 124 232 I need to create a constraint/ index to guarantee that the values of are unique if different to null, I cannot create a unique index because I have got a Key violation (due to the ...more >>

SQL Server 2000 stored procedure numeric value
Posted by koumides NO[at]SPAM gmail.com at 4/8/2005 5:01:35 AM
Hello All, I have a stored procedure that has an argument @search_criterion. Now is there a way to check whether that argument has only number data or if there are characters as well. Many thanks, Marios Koumides...more >>

Creating a job with many steps including DTS
Posted by Scott at 4/8/2005 4:37:29 AM
Hi, (using Windows 2000 Server/SQL2K Ent Ed SP3a) I am looking to create a job with a number of steps inside it. I need the job to run on a sunday afternoon when our OLTP system is at our quietest in terms of user connections and throughput. The job purpose is to copy data (24,000,000 rows...more >>

Select statement returns different results
Posted by ryanbreakspear NO[at]SPAM gmail.com at 4/8/2005 4:06:21 AM
Hi Guys, I appreciate that giving an answer to this might be difficult because I haven't posted the table schema, but the problem I'm getting only happens because there is a lot of data in the table. I'm running the statement: select count(*) from table1 where column1 in('A','B','C') ...more >>

Create Stored Procedure error with temp table
Posted by at 4/8/2005 3:25:02 AM
I'm trying to build a new script to create a Stored Procedure. As part of the SP it creates two temporay tables, populates them and then return the resulting data. It then drops the tables. If I run the contents of the Create SP script (i.e. the actual bit that does something) it's fine. But,...more >>

Calculating space
Posted by Mal at 4/8/2005 3:11:02 AM
Hi Problem - I want to create a query that give me this results Table, Column , Datatype, Rowcount, Size. I have a question though, I've read in BOL about how to calculate space based on variable and fixed lengths of datatypes. What I am not sure about is how to sql allocate space. Le...more >>

transform capitalized words to properly cased
Posted by nonno at 4/8/2005 12:15:02 AM
hi, I want to ask about how to transform capitalized words to properly cased, e.g. user input: HI ALL! I'M A NEWBIE! output: Hi all! I'm a newbie! How to do that?...more >>

Ordering by a Derived Column
Posted by gopi at 4/8/2005 12:00:00 AM
Hello All, When I run the following query against Northwind..Orders table I get the output in the following format : WhichQuarter QuarterlyTotal ------------- -------------- FirstQuarter 274 FourthQuarter 202 SecondQuarter 181 ThirdQu...more >>

UPDATE Command
Posted by Leila at 4/8/2005 12:00:00 AM
Hi, I need to update my table using its own data. Suppose that we add another field(BossName) to Employees table in Northwind. Now I want to update its value with the name of each employee's boss. I have written this TSQL command but I'm not sure if this is the best: update employees set Boss...more >>

identity fields - losing values
Posted by Chris Strug at 4/8/2005 12:00:00 AM
Hi, I've an application that consists of a of main table. Each record requires a numeric reference and these references must be sequential with no gaps. At the moment, this reference field is of an identity type. This works fine most of the time, however every now and again the identity fiel...more >>

cross reference of database
Posted by AM at 4/8/2005 12:00:00 AM
Hi all gurus From Pubs database I want to get some ObjectProperty value from NorthWind ObjectProperty(<object id of Northwind DB> , <property>) Is it possible? Thanks ...more >>

how to select distinct values
Posted by Nina Harris at 4/8/2005 12:00:00 AM
posting this on behalf of someone else, the question is how to produce the output in such a way as to get a Count(*) for Distinct dates from the sample query below this is what we have so far SELECT DATEADD(ss, time_stamp, '1970-01-01 00:00:00') AS Expr1, CONVER...more >>

Multiple Cascade Paths Error
Posted by Adrian Parker at 4/8/2005 12:00:00 AM
Can anyone tell me why on earth you can't have two cascade paths to a table ? This essentially means we cannot use RI and have to maintain triggers for our DB. I see that they haven't fixed it in 2005 either. ...more >>

copying stored procedures
Posted by Gav at 4/8/2005 12:00:00 AM
Hi All, I have a small problem.... I need to replace stored procedures in an SQL database with ones from another database without touching any of the tables or data is there a way I can do this? Any help would be great Thanks Gav ...more >>

Need some advice. Thank You.
Posted by Shapper at 4/8/2005 12:00:00 AM
Hello, Today I am creating my first one-to-many relationship database. My main table is: USERS Then I have 4 tables related with this one: PAYMENTS, ORDERS, BOOKS, ARTICLES For each user I need to create a field named VALUE. VALUE = N(PAYMENTS)*4 + N(ORDERS)*2 + N(BOOKS)*10 + N(ARTICL...more >>

case join statement
Posted by simon at 4/8/2005 12:00:00 AM
I have parameter @cona. If @cona=1 then ................ from lokStanje l INNER JOIN (objSta Sc INNER JOIN artCona Ac ON Sc.ART_SIF=Ac.ART_SIF AND Sc.STA_OZN=@STA_OZN INNER JOIN LOKCONA Lc ON Ac.CONA=Lc.CONA) ON l.LOK_OZN=Lc.LOK_OZN LEFT JOIN ................. If @cona=0 then--I don't...more >>

SQL Profiler Exception Error
Posted by DMP at 4/8/2005 12:00:00 AM
Hi, I Execute & Trace through SQL Profiler the following SQL Statments though It is working fine : create table #Temp (id int,Name Varchar(100),Xtype char(4)) insert into #Temp select so.Id ,so.Name,so.xtype from dbo.sysobjects so select * from #Temp drop table #Temp SQL Profiler Report...more >>


DevelopmentNow Blog