Can the same logic be applied in sql stored procedure itself to get the same result as done in the following link post instead of using LINQ?
Linq query having group by
This is my stored procedure
CREATE PROC [dbo].[WF_SPScanningReport_S]
(
#COMPANYID VARCHAR(20),
#FROMDATE DATETIME,
#TODATE DATETIME,
#FromRecord int,
#ToRecord int,
#SortString varchar(200)
)
AS
BEGIN
declare #Query nvarchar(Max)
if(ISNULL(LTRIM(RTRIM(#SortString)),'') <> '')
set #SortString='order by '+#SortString
else
set #SortString='order by IMAGEID'
SET NOCOUNT ON
set #Query=' CREATE TABLE #TABLE
(IMAGEID INT ,
SCANDATE DATETIME,
COUNT INT
)
INSERT INTO #TABLE(IMAGEID , SCANDATE)
SELECT IMAGEID , CAST(CONVERT(VARCHAR(10), SCAN_DATE,101) AS DATETIME) SCANDATE FROM WF_IMAGES
WHERE COMPANYID='''+#COMPANYID+''' AND SCAN_DATE BETWEEN '''+cast(#FromDate as varchar)+''' AND '''+cast(#ToDate as varchar)+''' AND IMAGE_NAME <> ''BLANK.PDF'' AND ISNULL(''Reviewed'','''') <> ''X''
UPDATE #TABLE
SET COUNT = S.COUNT1
FROM #TABLE T, (SELECT COUNT(SCANDATE) AS COUNT1 ,SCANDATE FROM #TABLE GROUP BY SCANDATE) S
WHERE T.SCANDATE= S.SCANDATE
SELECT * FROM (SELECT Distinct row_number() over ('+#SortString+') as RowNum,
IMAGEID, SCANDATE, COUNT FROM #TABLE )AS RowConstrainedResult
Where RowNum >'+cast(#FromRecord as varchar)+' AND RowNum <= '+cast (#ToRecord as varchar)+'
DROP TABLE #TABLE '
exec (#Query)
PRINT #Query
SET NOCOUNT OFF
END
This is my SP result
RowNum IMAGEID SCANDATE COUNT
1 10000131 2012-07-04 00:00:00.000 1
2 10002626 2012-08-03 00:00:00.000 1
3 10003348 2012-09-06 00:00:00.000 1
4 10003589 2012-09-15 00:00:00.000 8
5 10003590 2012-09-15 00:00:00.000 8
6 10003591 2012-09-15 00:00:00.000 8
7 10003592 2012-09-15 00:00:00.000 8
8 10003595 2012-09-15 00:00:00.000 8
9 10003596 2012-09-15 00:00:00.000 8
10 10003598 2012-09-15 00:00:00.000 8
11 10003599 2012-09-15 00:00:00.000 8
12 10004808 2012-09-20 00:00:00.000 14
13 10004809 2012-09-20 00:00:00.000 14
14 10004810 2012-09-20 00:00:00.000 14
15 10004811 2012-09-20 00:00:00.000 14
16 10004812 2012-09-20 00:00:00.000 14
17 10004813 2012-09-20 00:00:00.000 14
18 10004814 2012-09-20 00:00:00.000 14
19 10004815 2012-09-20 00:00:00.000 14
20 10004816 2012-09-20 00:00:00.000 14
21 10004817 2012-09-20 00:00:00.000 14
22 10004818 2012-09-20 00:00:00.000 14
23 10004819 2012-09-20 00:00:00.000 14
24 10004820 2012-09-20 00:00:00.000 14
25 10004823 2012-09-20 00:00:00.000 14
26 10006686 2012-09-21 00:00:00.000 3
27 10006687 2012-09-21 00:00:00.000 3
28 10006689 2012-09-21 00:00:00.000 3
29 10006806 2012-09-27 00:00:00.000 1
30 10006816 2012-09-28 00:00:00.000 1
31 10006840 2012-10-02 00:00:00.000 1
32 10006877 2012-10-03 00:00:00.000 1
33 10006923 2012-10-05 00:00:00.000 3
34 10006936 2012-10-05 00:00:00.000 3
35 10006937 2012-10-05 00:00:00.000 3
36 10620408 2013-03-11 00:00:00.000 1
37 10622755 2013-07-01 00:00:00.000 8
38 10622756 2013-07-01 00:00:00.000 8
39 10622761 2013-07-01 00:00:00.000 8
40 10622765 2013-07-01 00:00:00.000 8
41 10622771 2013-07-01 00:00:00.000 8
42 10622772 2013-07-01 00:00:00.000 8
43 10622773 2013-07-01 00:00:00.000 8
44 10622774 2013-07-01 00:00:00.000 8
45 10622891 2013-07-02 00:00:00.000 14
46 10622892 2013-07-02 00:00:00.000 14
47 10622893 2013-07-02 00:00:00.000 14
48 10622895 2013-07-02 00:00:00.000 14
49 10622896 2013-07-02 00:00:00.000 14
50 10622897 2013-07-02 00:00:00.000 14
51 10622898 2013-07-02 00:00:00.000 14
52 10622899 2013-07-02 00:00:00.000 14
53 10622900 2013-07-02 00:00:00.000 14
54 10622901 2013-07-02 00:00:00.000 14
55 10622902 2013-07-02 00:00:00.000 14
56 10622903 2013-07-02 00:00:00.000 14
57 10622904 2013-07-02 00:00:00.000 14
58 10622905 2013-07-02 00:00:00.000 14
59 10622931 2013-07-03 00:00:00.000 10
60 10622932 2013-07-03 00:00:00.000 10
61 10622933 2013-07-03 00:00:00.000 10
62 10622946 2013-07-03 00:00:00.000 10
63 10622950 2013-07-03 00:00:00.000 10
64 10622951 2013-07-03 00:00:00.000 10
65 10622952 2013-07-03 00:00:00.000 10
66 10622953 2013-07-03 00:00:00.000 10
67 10622954 2013-07-03 00:00:00.000 10
68 10622956 2013-07-03 00:00:00.000 10
69 10622979 2013-07-04 00:00:00.000 5
70 10622980 2013-07-04 00:00:00.000 5
71 10622981 2013-07-04 00:00:00.000 5
72 10623017 2013-07-04 00:00:00.000 5
73 10623018 2013-07-04 00:00:00.000 5
74 10623026 2013-07-05 00:00:00.000 9
75 10623027 2013-07-05 00:00:00.000 9
76 10623028 2013-07-05 00:00:00.000 9
77 10623029 2013-07-05 00:00:00.000 9
78 10623030 2013-07-05 00:00:00.000 9
79 10623031 2013-07-05 00:00:00.000 9
80 10623032 2013-07-05 00:00:00.000 9
81 10623033 2013-07-05 00:00:00.000 9
82 10623034 2013-07-05 00:00:00.000 9
83 10623059 2013-07-08 00:00:00.000 7
84 10623060 2013-07-08 00:00:00.000 7
85 10623061 2013-07-08 00:00:00.000 7
86 10623062 2013-07-08 00:00:00.000 7
87 10623063 2013-07-08 00:00:00.000 7
88 10623064 2013-07-08 00:00:00.000 7
89 10623065 2013-07-08 00:00:00.000 7
90 10623107 2013-07-09 00:00:00.000 1
91 10623112 2013-07-10 00:00:00.000 5
92 10623113 2013-07-10 00:00:00.000 5
93 10623122 2013-07-10 00:00:00.000 5
94 10623123 2013-07-10 00:00:00.000 5
95 10623124 2013-07-10 00:00:00.000 5
96 10623142 2013-07-12 00:00:00.000 2
97 10623143 2013-07-12 00:00:00.000 2
98 10623172 2013-07-15 00:00:00.000 17
99 10623173 2013-07-15 00:00:00.000 17
100 10623174 2013-07-15 00:00:00.000 17
101 10623175 2013-07-15 00:00:00.000 17
102 10623176 2013-07-15 00:00:00.000 17
103 10623177 2013-07-15 00:00:00.000 17
104 10623178 2013-07-15 00:00:00.000 17
105 10623179 2013-07-15 00:00:00.000 17
106 10623180 2013-07-15 00:00:00.000 17
107 10623181 2013-07-15 00:00:00.000 17
108 10623182 2013-07-15 00:00:00.000 17
109 10623183 2013-07-15 00:00:00.000 17
110 10623184 2013-07-15 00:00:00.000 17
111 10623185 2013-07-15 00:00:00.000 17
112 10623186 2013-07-15 00:00:00.000 17
113 10623187 2013-07-15 00:00:00.000 17
114 10623188 2013-07-15 00:00:00.000 17
115 10623195 2013-07-16 00:00:00.000 27
116 10623196 2013-07-16 00:00:00.000 27
117 10623199 2013-07-16 00:00:00.000 27
118 10623200 2013-07-16 00:00:00.000 27
119 10623203 2013-07-16 00:00:00.000 27
120 10623204 2013-07-16 00:00:00.000 27
121 10623206 2013-07-16 00:00:00.000 27
122 10623207 2013-07-16 00:00:00.000 27
123 10623212 2013-07-16 00:00:00.000 27
124 10623213 2013-07-16 00:00:00.000 27
125 10623214 2013-07-16 00:00:00.000 27
126 10623215 2013-07-16 00:00:00.000 27
127 10623216 2013-07-16 00:00:00.000 27
128 10623217 2013-07-16 00:00:00.000 27
129 10623218 2013-07-16 00:00:00.000 27
130 10623223 2013-07-16 00:00:00.000 27
131 10623225 2013-07-16 00:00:00.000 27
132 10623227 2013-07-16 00:00:00.000 27
133 10623228 2013-07-16 00:00:00.000 27
134 10623229 2013-07-16 00:00:00.000 27
135 10623230 2013-07-16 00:00:00.000 27
136 10623231 2013-07-16 00:00:00.000 27
137 10623232 2013-07-16 00:00:00.000 27
138 10623234 2013-07-16 00:00:00.000 27
139 10623236 2013-07-16 00:00:00.000 27
140 10623237 2013-07-16 00:00:00.000 27
141 10623238 2013-07-16 00:00:00.000 27
142 10623240 2013-07-17 00:00:00.000 6
143 10623241 2013-07-17 00:00:00.000 6
144 10623242 2013-07-17 00:00:00.000 6
145 10623244 2013-07-17 00:00:00.000 6
146 10623247 2013-07-17 00:00:00.000 6
147 10623248 2013-07-17 00:00:00.000 6
148 10623841 2013-09-11 00:00:00.000 2
149 10623848 2013-09-11 00:00:00.000 2
150 10623921 2013-09-20 00:00:00.000 2
151 10623923 2013-09-20 00:00:00.000 2
152 10624106 2013-10-09 00:00:00.000 3
153 10624108 2013-10-09 00:00:00.000 3
154 10624116 2013-10-09 00:00:00.000 3
155 10624521 2013-11-23 00:00:00.000 2
156 10624523 2013-11-23 00:00:00.000 2
157 10625218 2013-12-31 00:00:00.000 2
158 10625219 2013-12-31 00:00:00.000 2
159 10625220 2014-01-02 00:00:00.000 1
160 10625245 2014-01-07 00:00:00.000 5
161 10625247 2014-01-07 00:00:00.000 5
162 10625250 2014-01-07 00:00:00.000 5
163 10625251 2014-01-07 00:00:00.000 5
164 10625252 2014-01-07 00:00:00.000 5
165 10625266 2014-01-09 00:00:00.000 1
And I need something like this
11/27/2007 12:00:00 AM 1001527,1001528,1001529,1001530,1001531,1001532,1001533,1001534,1001535,1001536,1001537,1001538,1001539,1001540,1001541,1001542 16
11/20/2008 12:00:00 AM 1002501,1002502,1002503,1002504,1002505,1002506,1002507,1002508,1002509,1002510,1002511,1002512,1002513,1002514,1002515,1002516,1002517,1002518,1002519,1002520 20
7/5/2011 12:00:00 AM 1015237,1015238 2
7/6/2011 12:00:00 AM 1015248,1015249,1015259,1015260,1015286,1015287,1015288,1015289,1015290,1015291,1015292,1015293 12
First column has scandate on which Group By is done, Second has image ids having same scan date in single cell - comma seperated, and lastly count colimn with count of image ids in single cell
The querstion comma delimited list as a single string, T-SQL provides an illustration of how you can get a comma-delimited list grouped by a particular field.
The following code-snippet shows how you could take your resultant dataset and pivot it as illustrated in question above.
select distinct t1.scantime,
STUFF(
(SELECT ',' + convert(varchar(10), t2.ImageId, 120)
FROM yourtable t2
where t1.scantime = t2.scantime
FOR XML PATH (''))
, 1, 1, '') AS imageids
from yourtable t1
However, you will want to refactor your existing stored proc, so that you are not doing unnecessary intermediate queries to get to this result.
Related
I am trying to distribute a set of items across number of buckets. I am looking for following properties:
Bucket assignment needs to be deterministic. In different runs same
input should end up in the same bucket.
Distribution of data between buckets should be uniform.
This should work for fairly small number of inputs (e.g. if I want
to distribute 50 inputs across 25 buckets ideally each bucket will
have 2 items).
First try was to generate md5 from input data and form bucket from first bytes of md5. I am not too satisfied with uniformity. It works well when input is large but not so well for small input. E.g. distributing 100 items across 64 buckets:
List<string> l = new List<string>();
for (int i = 0; i < 100; i++)
{
l.Add(string.Format("data{0}.txt", i));
}
int[] buckets = new int[64];
var md5 = MD5.Create();
foreach (string str in l)
{
{
byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(str));
uint bucket = BitConverter.ToUInt32(hash, 0) % 64;
buckets[bucket % 64]++;
}
}
Any suggestions what could I do to achieve higher uniformity? Thanks.
Leaving aside the efficiency of using MD5 for this purpose (see the discussion here and in the marked duplicate of that question), basically the answer is that what you have is what a uniform distribution really looks like.
That might seem counter-intuitive, but it's easily demonstrable either mathematically or by experiment.
As a kind of motivating example, consider the task of choosing exactly 64 numbers in the range 0-63. The odds that you will get one per bucket are very close to 0. There are 6464 possible sequences, of which 64! contain all 64 numbers. The odds of getting one of these sequence is about one in 3.1×1026. In fact, the odds of getting a sequence in which no element appears three times is less than one in a thousand (it's about .000658). So it's almost certain that a random uniform sample of 64 numbers in the range 0-63 will have some triplets, and it's pretty likely that there will be some quadruplet. If the sample is 100 numbers, those probabilities just get even bigger.
But the maths are not so easy to compute in general, so here I chose to illustrate by experiment :-), using random.org, which is a pretty reliable source of random numbers. I asked it for 100 numbers in the range 0-63, and counted them (using bash, so my "graph" is not as pretty as yours). Here are two runs:
First run:
Random numbers:
44 17 50 11 16 4 24 29 12 36
27 32 12 63 4 30 19 60 28 39
22 40 19 16 23 2 46 31 52 41
13 2 42 17 29 39 43 9 20 50
45 40 38 33 17 45 28 6 48 12
56 26 34 33 35 40 28 44 22 10
50 55 49 43 63 62 22 50 15 52
48 54 53 26 4 53 13 56 42 60
49 30 14 55 29 62 15 13 35 40
22 38 37 36 10 36 5 41 43 53
Counts:
X X X
X XX X X XX X X X X X
X X X XX XXX X X X XXX X XX XXXXXXXX XXX XX XX X XX
X XXX XXXXXXXXX XX XXX XXXXXXXXXXXXXXXXXXXXX XXX XXXXX X XX
----------------------------------------------------------------
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6
0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2
Second run:
Random numbers:
41 31 16 40 1 51 17 41 27 46
24 14 21 33 25 43 4 36 1 14
40 22 11 22 30 19 23 63 39 61
8 55 40 6 21 13 55 13 3 52
17 52 53 53 7 21 47 13 45 57
25 27 30 48 38 55 55 22 61 11
11 28 45 63 43 0 41 51 15 2
33 2 46 14 35 41 5 2 11 37
28 56 15 7 18 12 57 36 59 51
42 5 46 32 10 8 0 46 12 9
Counts:
X X X X
X X XX XX XX X X X
XXX X XX XXXXX X XX X XX X X X XX X XX XXX X X X X
XXXXXXXXXXXXXXXXXXXX XXXXX XX XXXX XXXXXXXXX XXXX XXX XXX X X X
----------------------------------------------------------------
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6
0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2
You could try this with your favourite random number generator, playing around with the size of the distribution. You'll get the same sort of shape.
This question already has answers here:
Console.ReadLine() max length?
(10 answers)
Closed 5 years ago.
I have c# console application. I want to read user input separated by space but my console application stops reading space separated input after count 87. what is the reason.
for example below is the count 87.I want to read 90 inputs separated by space. and it stops reading inputs after count 87.
1 1 1 1 1 1 1 12 22 22 22 22 22 222 222 222 222 222 222 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 31 22 22 22 22 22 22 22 22 22 2 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 2 2 2 2 22 22 22 22 22.
My console application code is;
string[] temp = Console.ReadLine().Split(' ');
int[] height = Array.ConvertAll(height_temp, Int32.Parse);
above as accoding to above input 90. height should be 90 but it gives me height 87. infact it stops reading inputs after count 87.
There is a character limit for Console.ReadLine(). It should be 256 characters if I am not mistaken. So, you can increase the limit like that;
Console.SetIn(new StreamReader(Console.OpenStandardInput(),
Console.InputEncoding,
false,
bufferSize: 1024));
string[] temp = Console.ReadLine().Split(' ');
int[] height = Array.ConvertAll(temp, Int32.Parse);
This question already has an answer here:
Selection Sort trouble with indexes
(1 answer)
Closed 6 years ago.
Actually I'm dealing with CodeAbbey problem, so I don't want answer as code, but explenation about that, what I am doing wrong. http://www.codeabbey.com/index/task_view/selection-sort
My Selection Sort actually works without any problems, but I don't know why I do not get proper indexes (when sorting works!). I.e. for input data:5 1 3 6 2 4 7 9 8 0 I got it sorted to 0 1 2 3 4 5 6 7 8 9, as I wished.
Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelectionSort
{
class Program
{
static void Main(string[] args)
{
int howMany = int.Parse(Console.ReadLine()); //length of array
List<int> Base = new List<int>(Array.ConvertAll(Console.ReadLine().Split(), int.Parse)); //input to array (i.e. 5 1 3 6 2 4 7 9 8 0 => { 5, 1, 3, 6, 2, 4, 7, 9, 8, 0 })
List<int> Output = new List<int>(); // list to store sorted array
string[] ans = new string[howMany]; // array for storing answers
int loops = Base.Count();
for(int i = 0; i != loops; i++)
{
int topID = 0, topValue = 0;
for(int j = 0; j != Base.Count(); j++)
{
if (j == 0)
{
topID = 0;
topValue = Base[0];
}
else
{
if(topValue < Base[j])
{
topValue = Base[j];
topID = j;
}
}
}
ans[i] = topID.ToString(); //after looping through array save topID to answer array
Output.Add(Base[topID]); //add topValue to output
Base.RemoveAt(topID); //remove topValue with index topID from list
}
//Output.Reverse(); // Writing on stdout
//foreach(var s in Output) // sorted array
//{ //
// Console.Write(s + " "); // It works without any problems
//} //
//Console.ReadLine(); //
foreach(var s in ans)
{
Console.Write(s + " "); // write on stdout stored indexes
}
Console.ReadLine();
}
}
}
I.e. for such a test data:
124
144 146 4 121 106 142 153 168 122 42 135 127 126 16 193 52 29 161 186 83 152 72 51 125 37 116 187 133 183 132 80 53 185 129 7 189 98 128 32 33 56 157 49 50 10 77 11 196 160 162 68 43 14 181 112 113 94 100 165 79 172 159 156 57 9 6 66 86 17 63 46 178 130 88 192 124 105 182 34 18 76 155 24 89 123 12 179 109 188 13 40 5 163 45 27 85 103 93 69 58 25 81 145 92 30 138 154 177 158 140 91 171 139 67 175 184 120 8 54 147 84 174 95 55
I got it sorted to:
4 5 6 7 8 9 10 11 12 13 14 16 17 18 24 25 27 29 30 32 33 34 37 40 42 43 45 46 49 50 51 52 53 54 55 56 57 58 63 66 67 68 69 72 76 77 79 80 81 83 84 85 86 88 89 91 92 93 94 95 98 100 103 105 106 109 112 113 116 120 121 122 123 124 125 126 127 128 129 130 132 133 135 138 139 140 142 144 145 146 147 152 153 154 155 156 157 158 159 160 161 162 163 165 168 171 172 174 175 177 178 179 181 182 183 184 185 186 187 188 189 192 193 196
and I got such an indexes:
47 14 72 34 84 25 17 29 107 25 69 46 76 63 94 100 105 52 96 7 49 76 41 15 39 47 86 33 46 61 82 6 15 87 1 75 0 3 76 77 75 5 16 16 46 18 20 5 5 11 42 48 3 1 64 10 26 25 44 1 36 48 25 12 58 23 45 49 50 37 32 28 41 49 5 43 8 21 16 29 5 35 16 37 21 22 32 18 11 34 33 7 3 4 9 8 15 22 10 1 18 3 12 5 4 17 2 14 14 10 9 8 1 4 7 6 3 2 2 4 1 1 1 0
when I was supposed to get these:
47 14 74 35 88 26 18 32 115 28 77 53 86 71 107 28 74 60 86 7 58 92 49 17 48 61 28 41 62 81 60 6 20 88 1 6 0 5 74 53 5 10 27 29 72 33 37 11 12 23 12 53 8 3 32 25 55 54 0 4 11 41 57 36 14 56 28 56 8 5 12 8 41 35 19 19 30 14 45 29 21 28 35 37 5 32 19 11 19 30 26 31 15 22 21 28 3 11 19 9 6 9 11 5 15 7 16 3 3 10 12 3 3 8 1 6 6 3 4 3 1 0 1
What am I doing wrong?
Greetings
You should be swapping topValue with the last unsorted element instead of removing it. I guess you could remove it after swapping if you wanted. But if you don't remove it and you properly ignore the sorted elements, the original collection will be sorted at the end, so you won't have to make any Add() or Reverse() calls or create a new collection.
On this page, the sample code for C# contains the following code, where cardNumber is a string:
cardNumber.Select(c => c - '0').ToArray()
Now, what this appears to do is subtract 0 from each char in cardNumber, returning each as ints, then put them into an array. My questions, specifically about the c - '0' part of this code are:
1) Why does it do this? What is the underlying behavior/explanation?
2) Why would this be done instead of using Int32.Parse?
Note: Here is a similar question in C, this question may have the same/similar explanation.
It's subtracting unicode code points. So if c was something like 9 the operation is '9' - '0'. The code point for 9 is 57 and 0 is 48, so it will perform 57 - 48 which results in 9.
The only reason I can think of doing this over an int.Parse would be speed - this is an arithmetic operation which is much faster than whatever int.Parse does.
What Dave Zych points out in his answer is absolutely correct. This converts a string into an array of digits.
You often will see things like this done on embedded systems where parsing an int is an expensive operation. There is one significant flaw with this approach. (Other than that it's not immediately obvious to the uninitiated what it does.)
Consider what happens with the following input string:
اختبار
The resulting array comes out to
{ 1527, 1534, 1530, 1528, 1527, 1537 }
The failure when using this method is silent because اختبار is as valid a string as 123456. Using int.Parse, while it may be slower, will throw a FormatException to let you know that something went wrong.
While it is certainly acceptable in some cases to use the c - '0' method, just be sure when using it that you understand the risks, and make sure to test edge cases.
(For anyone who's interested the Arabic is 'test' translated using Google Translate)
Each character has a numerical representation so it can be stored in memory, and the c - '0' operation is simply subtracting the number that represents '0' from the number that represents the character held by c.
Hence, if c holds '5' the result of the operation will be the number 5.
Here is quick refrence to the ASCII printable code chart, to which Unicode is backward compatible:
Binary Oct Dec Hex Glyph
010 0000 040 32 20 (space)
010 0001 041 33 21 !
010 0010 042 34 22 "
010 0011 043 35 23 #
010 0100 044 36 24 $
010 0101 045 37 25 %
010 0110 046 38 26 &
010 0111 047 39 27 '
010 1000 050 40 28 (
010 1001 051 41 29 )
010 1010 052 42 2A *
010 1011 053 43 2B +
010 1100 054 44 2C ,
010 1101 055 45 2D -
010 1110 056 46 2E .
010 1111 057 47 2F /
011 0000 060 48 30 0
011 0001 061 49 31 1
011 0010 062 50 32 2
011 0011 063 51 33 3
011 0100 064 52 34 4
011 0101 065 53 35 5
011 0110 066 54 36 6
011 0111 067 55 37 7
011 1000 070 56 38 8
011 1001 071 57 39 9
011 1010 072 58 3A :
011 1011 073 59 3B ;
011 1100 074 60 3C <
011 1101 075 61 3D =
011 1110 076 62 3E >
011 1111 077 63 3F ?
100 0000 100 64 40 #
100 0001 101 65 41 A
100 0010 102 66 42 B
100 0011 103 67 43 C
100 0100 104 68 44 D
100 0101 105 69 45 E
100 0110 106 70 46 F
100 0111 107 71 47 G
100 1000 110 72 48 H
100 1001 111 73 49 I
100 1010 112 74 4A J
100 1011 113 75 4B K
100 1100 114 76 4C L
100 1101 115 77 4D M
100 1110 116 78 4E N
100 1111 117 79 4F O
101 0000 120 80 50 P
101 0001 121 81 51 Q
101 0010 122 82 52 R
101 0011 123 83 53 S
101 0100 124 84 54 T
101 0101 125 85 55 U
101 0110 126 86 56 V
101 0111 127 87 57 W
101 1000 130 88 58 X
101 1001 131 89 59 Y
101 1010 132 90 5A Z
101 1011 133 91 5B [
101 1100 134 92 5C \
101 1101 135 93 5D ]
101 1110 136 94 5E ^
101 1111 137 95 5F _
110 0000 140 96 60 `
110 0001 141 97 61 a
110 0010 142 98 62 b
110 0011 143 99 63 c
110 0100 144 100 64 d
110 0101 145 101 65 e
110 0110 146 102 66 f
110 0111 147 103 67 g
110 1000 150 104 68 h
110 1001 151 105 69 i
110 1010 152 106 6A j
110 1011 153 107 6B k
110 1100 154 108 6C l
110 1101 155 109 6D m
110 1110 156 110 6E n
110 1111 157 111 6F o
111 0000 160 112 70 p
111 0001 161 113 71 q
111 0010 162 114 72 r
111 0011 163 115 73 s
111 0100 164 116 74 t
111 0101 165 117 75 u
111 0110 166 118 76 v
111 0111 167 119 77 w
111 1000 170 120 78 x
111 1001 171 121 79 y
111 1010 172 122 7A z
111 1011 173 123 7B {
111 1100 174 124 7C |
111 1101 175 125 7D }
111 1110 176 126 7E ~
Is it possible to get this report format in sql. I tried various ways but no luck..any light on this would help me a lot.. I can get name, tickets from table but how can date wise report in sql. I dont want use any reports
NAME 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 (date)
smrithi 10 20 34 45 55 55 66 77 33 44 55 56 44 66 77 88 55 22 33 11 44 99 77 88 (tickets)
XYZ 10 20 34 45 55 55 66 77 33 44 55 56 44 66 77 88 55 22 33 11 44 99 77 88
this is what I tried ..
SELECT *
FROM
( SELECT CAST(DAY(t_date_time_issued) AS VARCHAR(4)) AS SaleDay,
CAST(MONTH(t_date_time_issued) AS VARCHAR(4)) AS SaleYear
FROM dbo.tickets) as ts
PIVOT
(
count(t_reference)
FOR SaleDay IN ( [1],[2],[3],[4],[5],[6],[7],[8],[9],
[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],
[22],[23],[24] ) ) AS pvt
Try something like this:
SELECT Name, [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24]
FROM
(
SELECT Name,
CAST(DAY(t_date_time_issued) AS VARCHAR(4)) AS SaleDay,
t_reference
FROM dbo.tickets) AS ts
PIVOT
(
count(t_reference)
FOR SaleDay IN ( [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24] )
) AS pvt
http://sqlfiddle.com/#!6/052ff/5