Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need just the first time the customer is read

Author  Topic 

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2010-10-26 : 13:40:28
HI I Have this table with many transactions records. I need a listing of the customer names. So I want to result set just the first occurance
SELECT TOP 1000 [company]
,[Item_number]
,[Quantity]
,[Price]
,[Customer]
,[Cust_Code]
,[Date_Created]
,[item_name]
,[Category]
,[Department]
,[Budget]
,[PO]
,[home_id]
,[DeliveryDate]
FROM [tech2].[dbo].[V_Dashboard_expenses]
order by company

company is the name o
i just want first occurance.

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-26 : 13:58:33
Which version of SQL Server you are using ?

If you are using 2005, then try the below select and let us know whether it meets your requirment or not.



Is this you are looking for :

Select top 1000 [company]
,[Item_number]
,[Quantity]
,[Price]
,[Customer]
,[Cust_Code]
,[Date_Created]
,[item_name]
,[Category]
,[Department]
,[Budget]
,[PO]
,[home_id]
,[DeliveryDate]
From
(
SELECT Row_number() over (order by [Date_Created]) as Srno, [company]
,[Item_number]
,[Quantity]
,[Price]
,[Customer]
,[Cust_Code]
,[Date_Created]
,[item_name]
,[Category]
,[Department]
,[Budget]
,[PO]
,[home_id]
,[DeliveryDate]
FROM [tech2].[dbo].[V_Dashboard_expenses]) as SubTab
where SubTab.Srno = 1
order by company
Go to Top of Page

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2010-10-28 : 14:50:28
HI thanks for responsing. We are using sql server 2008 r2.
I am getting a syntax error with your codes.


"Msg 207, Level 16, State 1, Line 18
Invalid column name 'company'.
"
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-29 : 06:41:22
quote:
Originally posted by AdamWest

HI thanks for responsing. We are using sql server 2008 r2.
I am getting a syntax error with your codes.


"Msg 207, Level 16, State 1, Line 18
Invalid column name 'company'.
"



Hi,

Its not syntax error. It says that company column is not found in table [tech2].[dbo].[V_Dashboard_expenses].

I have taken it from your original post. Check whether company column exists in table or not.

If it exists, one possiblity is that the collation is case sensitive. Try to use the same case as found in table structure.
Go to Top of Page
   

- Advertisement -