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 2005 > threads for tuesday october 25

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

Returning rows as columns
Posted by Karthik at 10/25/2005 11:29:03 PM
Hi, I have two tables ItemMaster and ItemCondition. One item can have multiple conditions in the form of rows in ItemCondition. But while returning these, I would like to return it in the form of columns. Is that possible? Below is the DDL of my table structure CREATE TABLE [dbo].[ItemC...more >>


Database Restore Fails
Posted by Ghulam Farid at 10/25/2005 11:22:35 PM
HI to All! I have posted previously that database resotre giving me Device Activation Error which is solved. Now it is giving me the following error: Server: Msg 3270, Level 16, State 1, Line 1 An internal consistency error occurred. Contact Technical Support for assistance. Server: Msg 301...more >>

Device Activation error: Database Restores Fails
Posted by Ghulam Farid at 10/25/2005 10:59:31 PM
Hi to All! I m trying to restore a data base but it gives me the following error: Server: Msg 5105, Level 16, State 2, Line 1 Device activation error. The physical file name 'c:\Data\MyDB_Data.mdf' may be incorrect. Server: Msg 3156, Level 16, State 1, Line 1 File 'MyDB_Data' cannot be r...more >>

collation issue
Posted by Chris at 10/25/2005 7:34:59 PM
Hi I have a problem with collation orders as follows. The server collation order is set to Latin1_General_CI_AS. How ever a few databases, a small number, have the collation order of SQL_Latin1_General_CI_AS. Now, when some operations are requested from the interograting App, involvi...more >>

Duplicate records - no error message?
Posted by Priya Henry at 10/25/2005 7:20:01 PM
Hi, I am in the process of moving my back end to the SQL server. I have a test version in the SQLserver and the front end is in Access 2000 with linked tables. When the user enters a duplicate key (primary key) and the user tries to save the record in Access (using a save button), an erro...more >>

Exclusive OR condition needed for Check Constraint
Posted by Laurence Neville at 10/25/2005 6:00:55 PM
I want to put a check constraint on a table to enforce the following condition: Of four columns A, B, C, D one must have a value and the other three must be null. A is a varchar column, the others are integer. It seemed like I needed to create a bitwise Exclusive OR expression, with some...more >>

Access 2003 iif function
Posted by magikgb via SQLMonster.com at 10/25/2005 5:59:56 PM
Can someone tell me how i can create an iif function to do the following? I need to look a field that has an amount in it. if it is 90K or less make it 1 if its 180 to 90001 make it 2 etc... So for every 90K in that amount add 1.. I tried to do a VB code to create a ceiling funciton but Ac...more >>

How to write SELECT with IF?..
Posted by Vycka at 10/25/2005 5:27:54 PM
Hi, I need help with writing an SQL command. I need SELECT command with IF..ELSE senteces inside and I'm getting an error: "Incorrect syntax near the keyword 'if'." It should look something like this: SELECT column1, column2, (IF (1=1) SELECT 'Ok') FROM Table WHERE column1 = 3 Can an...more >>



basic question
Posted by ichor at 10/25/2005 5:21:15 PM
hi i have the following variables. declare @viStock int set @viStock = 1000 declare @vdStartDate datetime declare @vdEndDate datetime set @vdStartDate = getdate() set @vdEndDate = dateadd(week, 10, getdate()) i want to insert into a temp ttable the following amount date 100 24-10-2...more >>

Any work around to pass parameters to OPENQUERY
Posted by Saji at 10/25/2005 4:57:02 PM
I need to query a linked server which contains a table of million records and need to fetch only the relevant records from the linked server. Any ideas? Please help...more >>

Best practices for Unicode column supporting mixed languages and searching
Posted by Seth at 10/25/2005 3:40:15 PM
(I posted this to sqlserver.server newsgroup but did not get a helpful response) Globalization gurus, The problem is storing in a single column character data from mixed languages and then providing a search capability to find the best match given a search string in some arbitrary language...more >>

Query job steps
Posted by Patreek at 10/25/2005 3:37:03 PM
Hi, I'm trying to find out if any scheduled jobs use a file that is coming in from a main frame job overnight. All of the people who would know anything about this file were laid off, so now I'm supposed to clean up things. We have 73 sql servers where I work, and I'm looking to query eac...more >>

Getting more precise error messages, and setting default 'COLLATE'
Posted by Kim Noer at 10/25/2005 3:34:45 PM
Hi there, I've fiddling with a query, and somewhere I made an error - Server: Msg 8152, Level 16, State 2, Procedure kn_insertCust, Line 25 String or binary data would be truncated. The statement has been terminated. Line 25 points to the first line in the query, and since it's INSERT cus...more >>

Programatically stop a query in C#??
Posted by JP at 10/25/2005 3:24:02 PM
How can I do this so that if the user hits a cancel button, I can issue a SQL command to stop the query execution for that users' session ???. Ive configured the connection by default for a 90 sec time out, but they can still navigate other places leaving the query to run the full 90 secs when...more >>

Remove Newline characters from Text or Varchar (8000)Datatype
Posted by Disney at 10/25/2005 3:01:03 PM
I have a situation where I am casting text to varchar(8000) but it is not removing the newline characters in the Text data. How can we can do that ?...more >>

Help with complicated query...
Posted by crbd98 NO[at]SPAM yahoo.com at 10/25/2005 2:57:37 PM
Hello All, I have a simple table that stores messages of different types from different sources. The definition of the table is shown below. I need to devise an efficient query to return a "list of the N more recent messages for a subset of sources within a specified time frame." create tab...more >>

What does "Bad variable type" mean? [moved from another forum]
Posted by JeremyGrand at 10/25/2005 2:47:40 PM
I'm running a stored proc against MS SQL from my Delphi7 app with several parameters. . Program executes fine on win xp, fails on 2k. The exception message is "Bad variable type". Jeremy ...more >>

NEWBIE: FUNCTION that returns CHAR
Posted by Randy at 10/25/2005 2:32:13 PM
Hello NG Why wont this work? CREATE FUNCTION HBAisleRecords RETURNS CHAR(2) AS BEGIN RETURN 'AB' END How can I return a string value? I want to SELECT 2 charaters from a field in a record and return those characters to a stored procedure can this be done? TIAFAH Randy ...more >>

Working week Diary
Posted by John at 10/25/2005 1:50:53 PM
Can anyone please advise: What the easiest way of making a diary showing working days in SQL. I want to pass a month and year to a stored procedure and have it create a diary for the month showing working days that i can set data against before returning the recordset Regards John ...more >>

How to get 2 and 5 max number in the table?
Posted by Mani at 10/25/2005 1:45:38 PM
*** Sent via Developersdex http://www.developersdex.com ***...more >>

Group column name problem
Posted by tshad at 10/25/2005 1:38:19 PM
How would you do this statement: Select rank=count(*), Case when ProductTypeID = 1 then j.ItemName when ProductTypeID = 2 then r.ItemName end as Description, Price, PurchaseQty, TotalPrice = Price * PurchaseQty from PurchaseDetail pd join PurchaseMaster pm on (pd.PurchaseMasterID = pm.Pur...more >>

cursor
Posted by Hrvoje Voda at 10/25/2005 1:23:31 PM
What' s wrong with this code? Declare @UDName varchar(150) Declare @UName varchar(50) Declare @Domain varchar(50) Declare @EMail varchar(20) Declare @GName varchar(50) Declare @Description varchar(150) Declare @FName varchar(50) Declare @ShortName varchar(150) Declare UserCursor Cursor ...more >>

Creating a VIEW
Posted by will at 10/25/2005 12:14:04 PM
I'm trying to create a view in EM. SELECT TOP 100 PERCENT dbo.wf_styles.code, dbo.wf_styles.SA_Active, dbo.wf_bom.raw_type, dbo.wf_bom.raw_code, dbo.wf_bom.qty FROM dbo.wf_styles LEFT OUTER JOIN dbo.wf_bom ON dbo.wf_styles.code = dbo.wf_bom.style_code AND ...more >>

How to grab the average of a percentage
Posted by tran.loan NO[at]SPAM gmail.com at 10/25/2005 12:05:22 PM
I'm selecting an ID, the count of the ID, and then the percentage of that count. Something like this: DECLARE @TOTAL NUMERIC SELECT @TOTAL = COUNT(*) FROM #TABLE WHERE ID IN (27) SELECT ID, [COUNT] = SUM( CASE WHEN ID IN(27) THEN 1 ELSE 0 END), [PERCENT] = (CAST(CAST(ROUND(((sum(CASE WH...more >>

How to grab the average of a percentage
Posted by tran.loan NO[at]SPAM gmail.com at 10/25/2005 12:05:22 PM
I'm selecting an ID, the count of the ID, and then the percentage of that count. Something like this: DECLARE @TOTAL NUMERIC SELECT @TOTAL = COUNT(*) FROM #TABLE WHERE ID IN (27) SELECT ID, [COUNT] = SUM( CASE WHEN ID IN(27) THEN 1 ELSE 0 END), [PERCENT] = (CAST(CAST(ROUND(((sum(CASE WH...more >>

Connection problems from VB
Posted by Tor Inge Rislaa at 10/25/2005 12:04:59 PM
When monitoring errors concerning connection and updating data on my MS SQL Server2000 from a VB application I get these errors. -2147467259 [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionWrite (send()). -2147467259 [Microsoft][ODBC SQL Server Driver]Connection error -2147...more >>

Blocked tables
Posted by simon at 10/25/2005 11:51:56 AM
From time to time I get blocked tables in my database and application stope working. So I try next example: declare @n int set @n=50 while @n>0 begin SELECT * FROM table1 INNER JOIN table2.... set @n=@n-1 end While this selects are working I try in other query analyzer w...more >>

Comparing data in two different tables
Posted by kurt sune at 10/25/2005 11:48:35 AM
I am trying to find an easy set based alghoritm for comparing data in two different tables. Given tables like this create table dbo.IwExclusions ( Id bigint not null, Number bigint not null, constraint IwExclusionsPKCO primary key clustered ...more >>

Showing only ten records
Posted by when sanity fades away... at 10/25/2005 11:23:03 AM
Hey! I wanted to show only 1 to 10 records (or the next 10 records ect,). I used 'select * from MyTable where Key between 1 and 10'. Key is a serial number that is automatically increased by one. One record has been deleted, so the first ten are really from 1 to 11 but my query shows only 9 (1 ...more >>

Row numbers in select statements
Posted by tshad at 10/25/2005 11:21:39 AM
Is there an easy way to do get a row number in each row in a select statement? Something like: select rownumber,description price from lineorder order by row number Thanks, Tom ...more >>

using INSERT statements in a function
Posted by Maurice at 10/25/2005 10:46:09 AM
I'm trying to create a function that insert data in a table and returns the primary key but I get the following error: Invalid use of side-effecting or time-dependent operator in 'INSERT' within a function. Here is my script: create function [dbo].[AddStateProvince] (@StateProvinceCode [nv...more >>

Verification
Posted by Chris at 10/25/2005 10:27:14 AM
Hi, Which is faster This (select evulates after) If(@amt <= (SELECT tran_amt from Transactions where trans_id = @trans_id)) or (select evaluates before) If(SELECT tran_amt from Transactions where trans_id) >=@amt Thanks ...more >>

use varible values from subquery in a case
Posted by Senna at 10/25/2005 10:16:07 AM
Using SQL Server 2000. I'm looking for an solution that does what the code below should do, according to me. :) Explaination: CREATE TABLE Table2 ( Id int, Table1Id int, Type char(4), TableId int, StartDate smalldatetime, EndDate smalldatetime ) The idea is th...more >>

Newbie needs help with simple query :-)
Posted by abd08 at 10/25/2005 10:12:07 AM
Hi All, I have been trying to learn and use SQL, and have learned quite a bit (relatively speaking!!). Still, cannot get the below query to work... if anyone could help out, I would be very grateful (and have learn't something new!!!) =) SELECT T0.ItemCode, T0.ItemName,T1.ItmsGrpNam, SUM(T3...more >>

INSERT SELECT?
Posted by Adam Knight at 10/25/2005 10:06:18 AM
Hi all, I am trying to run an INSERT SELECT statement. This should be an easy query!!! Code: SET IDENTITY_INSERT asmt_v1_areas ON INSERT INTO asmt_v1_areas ('asmt_v1_area_id','name','mid') SELECT assmnt_area_id, name, mid FROM assmnt_areas When i try to run this query i get an error m...more >>

NEWBIE: TOP PREDICATE HELP
Posted by Randy at 10/25/2005 9:29:28 AM
Hello NG I am trying to use a declared variable of datatype INT within a SELECT TOP n * FROM table WHERE clause ORDER BY column Statement. I keep getting an incorrect syntax near my variable. What am I doing wrong? IF @varPRFI > @varMinimumLabels SELECT TOP @varMinimumLabels * FRO...more >>

PAD and Left justify in T SQL
Posted by Joe at 10/25/2005 9:09:01 AM
Hi, Is it possible to PAD and justify output from a select statement? I have to build an input record from two fields in a table that I am concatenating together. The result is then going to be passed as a parameter value to a dll. The dll is looking for input of the form Field Name posit...more >>

Number of records
Posted by simon at 10/25/2005 9:00:00 AM
I would like to get all records from table1 which ID not exists in table2: select a.* from tabel1 a LEFT JOIN table2 b ON a.ID=b.ID WHERE b.ID is null I don't get any record. If I try: select a.* from tabel1 a LEFT JOIN table2 b ON a.ID=b.ID AND b.ID is null I get all records. W...more >>

How test if an entered value exist with and update trigger
Posted by apiazza NO[at]SPAM misag.it at 10/25/2005 8:56:24 AM
Dear Group, I have the following problem with an UPDATE trigger. I trigger a field (named CD_AccountPL) and i need to do some action depending if the entered value exist into a key formed by the triggered field itself plus a second field named CD_AccLocalPL. for example: ID CD_AccountPL ...more >>

How test if an entered value exist with and update trigger
Posted by apiazza NO[at]SPAM misag.it at 10/25/2005 8:54:33 AM
Dear Group, I have the following problem with an UPDATE trigger. I trigger a field (named CD_AccountPL) and i need to do some action depending if the entered value exist into a key formed by the triggered field itself plus a second field named CD_AccLocalPL. for example: ID CD_AccountPL ...more >>

cannot shrink transaction log
Posted by Joey Martin at 10/25/2005 8:45:41 AM
I have not been able to successfully shrink my transaction log. I'm receiving the infamous "the log file for database is full". I have tried: backup log database with truncate_only go dbcc shrinkfile (database _log,0) go I receive this message when I am importing a large excel spreadsheet...more >>

HELP with large databases (desprate)
Posted by JP at 10/25/2005 8:44:05 AM
We have an SQL server with 5 databases on it. Databases 1 - 4 share data with database 5. The SP in databases 1- 4 directly link via the query to database 5. These databases have tables anywhere from 1 to 40 million records per table. Database 5 is where mist of the multi million row tables...more >>

Cross Tab Query
Posted by Ballu at 10/25/2005 8:06:12 AM
Can anybody help me to write Cross Tab Query in SQL Server 2000. Thank you, ...more >>

A new one on me!
Posted by Snake at 10/25/2005 7:50:05 AM
I came across a select statement that has me all confused! There is a reference to a table in a case clause which does not appear anywhere else in the Select. In the example below, TableC is a regular database table which does not appear in the From or the where or anywhere else. I had no ide...more >>

Updating Microsft Access tables from SQL
Posted by bob at zachys at 10/25/2005 6:10:04 AM
I need to update some Access table from SQL. Is there anyway to connect to Access table and run the following query via a DTS package (I imported the tables into SQL to do some testing.) /* the access tables are HoldWithdrawalTracking, HoldOrderDetails_View*/ /*sql table tblHoldWithdrawalPU */...more >>

Help !!
Posted by Peter Newman at 10/25/2005 6:05:02 AM
Im going mad trying and failing to figure this out . running SQl server 2000 (sp3). I have had code snippets and examples thrown at me, yet im missing something fundermental .. if i use the following code in TSQL i get a sucess on the executon of the DTS Declare @Packagename varchar(255) ...more >>

How to find a string?
Posted by Mile at 10/25/2005 5:40:09 AM
I have a table caled 'Test' with column caled 'Msgtext' on SQL 2000. The column Msgtest have ca 800 000 rows. One ex. on some rows on Msgtext column is: -Oct 19 08:24:17 security[success] 538 SRV1 User Logoff: User Name:Rolf Domain: -Oct 20 10:56:17 security[success] 540 SRV2 User Name: Do...more >>

Many tables-> bad?
Posted by the friendly display name at 10/25/2005 5:31:02 AM
Currently, I can chose two ways to implement a function: The easy way would lead to many (300) tables. The harder way would lead to considerable fewer tables. Is there a reason to chose the harder way? Are there any penalties, if you have many tables (with few entries) compared to few table...more >>

How do I figure out time and date at the same time?
Posted by Enric at 10/25/2005 4:26:04 AM
Dear all, I've got some problems with date and time (very silly, I know) select * from crm_1 where log < datepart(yyyy,getdate()) and log < datepart(mm,getdate()) and log < datepart(dd,getdate()) The aforementioned query doesn't find this value: 2005-06-09 08:27:17.810 CREATE TABLE...more >>

Group by MonthEnd
Posted by dan_williams NO[at]SPAM newcross-nursing.com at 10/25/2005 3:38:22 AM
I have the following query which returns a sum of hours for each month for a specific year. select month(tDate) as month, sum(hours) as total from tablename where Year(tDate) = 2005 group by month(tDate) order by month This works ok, however, is there a way to specify the month start date ...more >>

Last Identity Value
Posted by SimonM at 10/25/2005 2:57:01 AM
IDENT_CURRENT returns the last identity value generated for a specific table in any session and any scope. @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes. --- I need the last identity generated for a specific table for the cu...more >>

SqlHelper Problem
Posted by Wayne Wengert at 10/25/2005 2:40:34 AM
I am tyring to use SqlHelper to execute a SP with some passed parameters. When I try the statement shown below I get an error "Object reference not set to an instance of an object" I suspect the connection string as I am not sure exactly what SqlHelper wants for that value? I've tried inclu...more >>

Sql Server 2005 - CLR integration question
Posted by Julia Beresford at 10/25/2005 2:18:01 AM
Hi Why do I have to compile a vb or cs file via the command line to integrate into Sql Server 2005. Why can't I include assembly compiled in Visual Studio? Many thanks Julia....more >>

How do I: NOT use Dynamic SQL for this Stored Procedure
Posted by Russell Mangel at 10/25/2005 1:39:00 AM
Is there anyway to write this SP, --NOT-- using Dynamic SQL? Please don't ask me why I need this query (it's wacky), I just do. Any solution that does not use Dynamic SQL would be appreciated. Please notice the Input and Output on the SP, I need to pass in a tablename and receive the Max Pr...more >>

Trying to maximise performance
Posted by Stephen at 10/25/2005 12:58:02 AM
Hi I would like to know if I can improve the performanace of a stored proc which I have written so I was wondering if someone could tell me if there is a better way of writing the following two pieces of logic Declare @Count bigint Select @Count = Count(*) from orders where orderid = 10 If ...more >>


DevelopmentNow Blog