SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help. count function perhaps?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/26/2012 :  12:03:59  Show Profile  Reply with Quote
here's my problem (current one).
I have a table in which there is a GIN column. There can be multiple GIN numbers that are the same. What i need to do is set the "COUNT" columns value equal to the number of GIN numbers that are the same. For instance, if i have four rows with GIN # '100', each "Count" value for that GIN number should indicate "4", and so on. How might i be populating the COUNT column in this case? DDL follows:

CREATE TABLE [dbo].[426warrants](
	[crt_dckno] [nvarchar](1500) NULL,
	[gin] [nvarchar](1500) NULL,
	[pin] [nvarchar](1500) NULL,
	[NAME] [nvarchar](1500) NULL,
	[type] [nvarchar](1500) NULL,
	[address 1] [nvarchar](1500) NULL,
	[address 2] [nvarchar](1500) NULL,
	[City] [nvarchar](1500) NULL,
	[State] [nvarchar](1500) NULL,
	[Zip] [nvarchar](1500) NULL,
	[Race] [nvarchar](1500) NULL,
	[Sex] [nvarchar](1500) NULL,
	[DOB] [nvarchar](1500) NULL,
	[Height] [nvarchar](1500) NULL,
	[Weight] [nvarchar](1500) NULL,
	[Eye_Color] [nvarchar](1500) NULL,
	[Hair_Color] [nvarchar](1500) NULL,
	[Driver_License] [nvarchar](1500) NULL,
	[SSN] [nvarchar](1500) NULL,
	[warrant_type] [nvarchar](1500) NULL,
	[Warrant type] [nvarchar](1500) NULL,
	[i_statute_code] [nvarchar](1500) NULL,
	[iseqno] [nvarchar](1500) NULL,
	[offense_dte] [nvarchar](1500) NULL,
	[statute_number] [nvarchar](1500) NULL,
	[text_desc] [nvarchar](1500) NULL,
	[charge_level] [nvarchar](1500) NULL,
	[charge_degree] [nvarchar](1500) NULL,
	[issue_date] [nvarchar](1500) NULL,
	[Judge] [nvarchar](1500) NULL,
	[Bond_Amount] [nvarchar](1500) NULL,
	[Reason] [nvarchar](1500) NULL,
	[Bond Remark] [nvarchar](1500) NULL,
	[<NullColumn 34>] [nvarchar](1500) NULL,
	[FSS_RecNo] [varchar](10) NULL,
	[ArrestReportUniqueFKey] [varchar](22) NULL,
	[BEGIN] [varchar](10) NULL,
	[ARRESTNO] [varchar](15) NULL,
	[ARRESTNOB] [varchar](15) NULL,
	[CHARGENUM] [int] NULL,
	[GOC] [varchar](1) NULL,
	[ACL] [varchar](1) NULL,
	[ACD] [varchar](1) NULL,
	[AON] [varchar](4) NULL,
	[FSN] [varchar](30) NULL,
	[COUNTS] [smallint] NULL,
	[FCICCODEV] [varchar](40) NULL,
	[FSDESC] [varchar](200) NULL,
	[ADN] [varchar](3) NULL,
	[DV] [bit] NULL,
	[HC] [bit] NULL,
	[UCR] [varchar](4) NULL,
	[NCIC] [varchar](4) NULL,
	[END] [varchar](10) NULL,
	[UCRTYPE] [int] NULL,
	[NIBRSTYPE] [int] NULL,
	[PRIORITY] [int] NULL,
	[CriminalGangActivity1] [int] NULL,
	[CriminalGangActivity2] [int] NULL,
	[CriminalGangActivity3] [int] NULL,
	[LocationType] [int] NULL,
	[UNIQUEKEY] [varchar](22) NULL,
	[FS] [bit] NULL,
	[ORD] [bit] NULL,
	[ATTY_NO] [varchar](15) NULL,
	[COURT_NO] [varchar](25) NULL,
	[CITATION] [bit] NULL,
	[WRITATT] [bit] NULL,
	[DOM_VIO_INJ] [bit] NULL,
	[ORDER_ARR] [bit] NULL,
	[XMITSORTDATE] [varchar](19) NULL,
	[ARR_INDICATE] [int] NULL,
	[PC] [bit] NULL,
	[CAPIAS] [bit] NULL,
	[AC] [bit] NULL,
	[BW] [bit] NULL,
	[FW] [bit] NULL,
	[PW] [bit] NULL,
	[JUVPU] [bit] NULL,
	[ACTIVITY] [varchar](1) NULL,
	[DRUGTYPE] [varchar](1) NULL,
	[AMOUNT] [varchar](30) NULL,
	[SECTION] [varchar](15) NULL,
	[TRANSMITTED] [bit] NULL,
	[DATE_ISSUED] [datetime] NULL,
	[BONDAMT] [money] NULL
) ON [PRIMARY]

GO

visakh16
Very Important crosS Applying yaK Herder

India
47189 Posts

Posted - 04/26/2012 :  12:19:47  Show Profile  Reply with Quote
you can use aggregate function using PARTITION BY

so to get count grouped by GIN use

COUNT(1) OVER (PARTITION BY GIN) AS GINCount

and include in your insert statement to populate count field

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/26/2012 :  12:23:12  Show Profile  Reply with Quote
Thanks Visakh!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47189 Posts

Posted - 04/26/2012 :  12:29:49  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000