It's been a year since I started mapping my island, Feridhoo in Google Maps. But due to lack of time, I have not been able to finish it completely. I was able to add all the roads and Island shape so far. Hopefully I'll finish editing this map before the end of this year.
Following lines of code is enough to write a string to a text file.
First, import the name space, system.IO Second, use following code snippet at anywhere in your application which has the requirement to write to a file. Using sr AsStreamWriter = New StreamWriter("myfile.txt", True) sr.WriteLine("Hello") End Using
Explaining the Highlights: 1. "myfile.txt" is the file name you want write to, can include file locations. if the file does not exists in the location, file will be created. 2. True ,means append to the file if file exist, use false to write new. 3. sr.WriteLine("Hello") , used to write to the file.
Recently i was working on a Ballot progress reporting system at my office. for that i have to generate a data set which has number of voters grouped by age group. This can be easily done at application level coding. But i wanted to have SQL query which directly out put these data for me as a SP.
Voting data is collected to this table
So here is what my query looks like.
SELECT ages.age_s +Sep.s+ages.age_e as AgeGroup ,COUNT(T)as Count FROM (SELECT ' - ' AS s) AS Sep CROSS JOIN (SELECT'18'ASage_s, '24'ASage_e UNIONALL SELECT'25'AS age_s, '34'AS age_e UNIONALL SELECT'35'AS age_s, '44'AS age_e UNIONALL SELECT'45'AS age_s, '54'AS age_e UNIONALL SELECT'55'AS age_s, '64'AS age_e UNIONALL SELECT'65'AS age_s, '74'AS age_e UNIONALL SELECT'75'AS age_s, '100'AS age_e) AS ages LEFT OUTER JOIN (SELECT ((DATEPART(year, CONVERT (date, GETDATE()) ))-(DATEPART(year, dob))) as T fromVotingInfo ) AS m ON T BETWEEN ages.age_s AND age_e GROUP by ages.age_s +Sep.s+ages.age_e ORDER BY ages.age_s +Sep.s+ages.age_e asc
Output of the above query
Explanation:
'age_s' and 'age_e' is boundary of age groups like 18-24,25-34
'dob' is the field name where i stored Dob of those who have voted
'VotingInfo' is the table name from where i collect date