tsql

Specific day of current month and current year from date time SQL Server 2005

Hello everyone i want search data from invoices and client by today date I'm using DateDiff() GETDATE() functions for example two tables 1 Client - ID int - Name Varcher 2 Invoice - ID int - ClientID int - date Datetime - Total money query Select * from client c inner join invoice i on c.id = i.ClientID WHERE DateD...

SQL Server 2005 metadata search to get stored procedure parameters

How do you get a list of the input parameters for a stored procedure using metadata in SQL Server 2005? I want to do a SELECt on it and then iterate through the variable names. ...

I need a SQL statement that returns the number rows in a table with a specific value.

I'm sure this will equate down to the use of the COUNT statement but I'm not very good at SQL. Here are my SQL Tables. Teams Table: TeamId TeamName RosterSpots ----------------------------------------------- 1 Miami Heat 12 2 New York Knicks 10 Players Table: PlayerId PlayerName ...

Anybody using SQL Source Control from Red Gate

Hi all, We have been looking into possible solutions for our SQL Source control. I just came across Red Gates SQL Source control and wondered if anyone has implemented it? I am going to download the trial and give it a shot, but just wanted to see if others have real experience. As always greatly appreciate the input --S ...

Can't create XML format file in SQL, bcp: unknown option A

I have tried many things, but I'm still not getting this to work. Here's the code: bcp RFID.dbo.ResultsDump format nul -t, -c -x -f C:\RFID.xml -S"ALBERTLAST-PC\SQLEXPRESS" -UAlbert Last -P -T All I want to do is create an XML format file from ResultsDump table, and the above statement doesn't even work. My username is "Albert Last" w...

Convert query to only use table once

I have the following query: select field1,field2 from #table1 left join (select field3, max (field4) as field2 from #table1 group by field3) a on #table1.field3 = a.field3 I want to change it so #table1 is only used once (and preferably the most efficient way also) Any ideas? Thanks! ...

Syntax for SQL Not In List?

I am trying to develop a T-SQL query to exclude all rows from another table "B". This other table "B" has 3 columns comprising its PK for a total of 136 rows. So I want to select all columns from table "A" minus those from table "B". How do I do this? I don't think this query is correct because I am still getting a duplicate record e...

solve numeric overflow problem when converting to float

I have a float value that i need to do some calculations on and insert into a numeric(9,2). However in rare (and likley erronous) cases there are some data anomolies and I end up with a value that will not fit into numeric(9,2). What is a good solution to this problem? Maybe just use 9999999.99 if the number is 9999999.99 or greater? A...

How to find range of a number where the ranges come dyamically from another table?

If I had two tables: PersonID | Count ----------------- 1 | 45 2 | 5 3 | 120 4 | 87 5 | 60 6 | 200 7 | 31 SizeName | LowerLimit ----------------- Small | 0 Medium | 50 Large | 100 I'm trying to figure out how to do a query to get a result similar to: PersonID | SizeName ------...

select in sql server 2005

I have a table follow: ID first end a 1 3 b 3 8 c 8 10 I want to select follow: ID first end a-c 1 10 But i can't do it. Please! help me. Thanks! ...

Remove duplicates - SQL server 2000-2005

Only for MSSQL 2000-2005 by SQL query and no stored procedures No cursors and temp tables The table create table my_table ( row_id int identity(1,1), _key varchar(20), _total decimal(18,2) ) Insert the data insert into my_table (_key,_total) Values('qwe',10) insert into my_table(_key,_total) Values ('qwe',10) insert into my_table(...

How to formulate T-SQL to exclude duplicates?

I am trying to develop a query to just return non-duplicate records so that I can add these to my database, but I keep getting the duplicate record error. I tried ur solution but am still getting duplicate error problem. I deleted the 35 rows which were duplicate. What else could be causing this? Here is my query. Part of the conf...

SQL Server - Delete unused rows

I need to get stored procedure (not standart, only custom) to delete unused rows table (table1) and some other tables (table2, table3, table4...- we don't know how many tables refers to table1 by FOREIGN KEY CONSTRAINT) can refers to this table. For example: СREATE PROCEDURE [dbo].[delete_on_constraints] @table varchar(36) – table name...

Retrieve current value of ARITHABORT

Hi, I'm debugging a strange behavior which seems to be related to ARITHABORT. How can I retrieve the current value of ARITHABORT for the active connection? cheers, Achim ...

Joining multiple Parent/Child records

I am doing some analysis on a Cisco ICM database looking specifically at transferred calls. Basically there is an ICRCallKey field which is a unique number generated at a peripheral gateway for each line logged in the table. I can tell when a call is transferred by looking at the ICRCallKeyParent and ICRCallKeyChild fields and seeing if...

database question

Hi, I have written a cursor like bellow : declare myCursor cursor for select productID, productName from products declare @productID int declare @productName nvarchar(50) open myCursor fetch next from myCursor into @productID,@productName print @productID print @productName set @productID=0 set @productName='' while @@FETCH_STATUS=0...

database question

Hi, I have written the bellow cursor : declare myCursor cursor for select productID, productName from products declare @productID int declare @productName nvarchar(50) open myCursor fetch next from myCursor into @productID,@productName print @productID print @productName set @productID=0 set @productName='' while @@FE...

Convert PLSQL Cursor FOR Loop Syntax to TSQL

I have some PLSQL code which loops through some logic: FOR I in cur1 LOOP SELECT value1, value2 FROM db1..table1 t1 END LOOP; Can anyone explain to me the syntax for doing this in TSQL? ...

How to formulate T-SQL to avoid PK constraint?

I am trying to develop a query to just return non-duplicate records so that I can add these to my database, but I keep getting this error: Msg 2627, Level 14, State 1, Line 1 Violation of PRIMARY KEY constraint 'PK_j5c_MasterMeasures'. Cannot insert duplicate key in object 'dbo.j5c_MasterMeasures'. The statement has been terminated. ...

Counting groups of data in SQL

I have a table of about 1.6M rows where the records have a unique (identity) ID and then also have a 8-character "code" field. The code field it used to group data into sets...all rows with the same code are in the same set. Each set should consist of 12 records, but it seems our data load was off and some sets are incomplete. I need ...