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.
Author |
Topic |
pankaj2910
Starting Member
31 Posts |
Posted - 2014-07-03 : 05:53:07
|
Hi, I have a table having codecode12345678213456784578961212345678213456782134567812347586I want result on the basis of first 2 digit the repeatation of code is count as 1. code count 12 2 21 1 45 1pankajrocks |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-07-03 : 06:08:07
|
SELECT LEFT(Code, 2), COUNT(*) FROM dbo.Table1 GROUP BY LEFT(Code, 2); Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
mhorseman
Starting Member
44 Posts |
Posted - 2014-07-03 : 06:15:02
|
The way I read OP's question, perhaps what he wants is something like:SELECT LEFT(Code, 2), COUNT(*) FROM (select distinct code from dbo.table1) x GROUP BY LEFT(Code, 2);Mark |
|
|
pankaj2910
Starting Member
31 Posts |
Posted - 2014-09-24 : 02:50:36
|
Hi,I have a table having codecode12345678213456784578961212345678213456782134567812347586I want result on the basis of first 2 digit the repeatation of code is count as 1. code1 code2 count12 34 221 34 145 78 1pankajrocks |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-09-24 : 14:59:19
|
SELECT SUBSTRING(Code, 1, 2) AS Code1, SUBSTRING(Code, 3, 2) AS Code1, COUNT(*) AS [Count] FROM dbo.Table1 GROUP BY SUBSTRING(Code, 1, 2), SUBSTRING(Code, 3, 2); Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|
|
|