« first day (1777 days earlier)      last day (2541 days later) » 
03:00 - 22:0022:00 - 23:00

3:04 AM
I just posted a question related to the one I asked earlier. It is stackoverflow.com/questions/43107753/…
I am trying to transform the first recordset into the second one in this example.
--drop table GroupIdentifierTest
go
Create table GroupIdentifierTest
(
RowId varchar(10),
[Delimiter] int
)

insert into GroupIdentifierTest
select 'a', 0 union all
select 'b', 0 union all
select 'c', 0 union all
select 'd', 1 union all
select 'e', 0 union all
select 'f', 1
select * from GroupIdentifierTest
delete GroupIdentifierTest
insert into GroupIdentifierTest
select 'a', 1 union all
select 'b', 1 union all
select 'c', 1 union all
select 'd', 2 union all
select 'e', 2 union all
select 'f', 2
 
 
2 hours later…
4:47 AM
hi @ChristopherJ.Grace
you can do something simpler
 
Hi Andy
Please be it so
 
there are too many UNION ALL
 
That's just to generate the test data
The question is how to generate the second recordset generated by that code from the first.
 
@christopher I had some trouble reading your code
CREATE TABLE GroupIdentifierTest
(
RowId VARCHAR(10),
[Delimiter] INT
)

INSERT INTO GroupIdentifierTest
SELECT 'a', 0 UNION ALL
SELECT 'b', 0 UNION ALL
SELECT 'c', 0 UNION ALL
SELECT 'd', 1 UNION ALL
SELECT 'e', 0 UNION ALL
SELECT 'f', 1
SELECT * FROM GroupIdentifierTest
;

DELETE GroupIdentifierTest
;

INSERT INTO GroupIdentifierTest
SELECT 'a', 1 UNION ALL
SELECT 'b', 1 UNION ALL
SELECT 'c', 1 UNION ALL
SELECT 'd', 2 UNION ALL
SELECT 'e', 2 UNION ALL
SELECT 'f', 2
SELECT r.RowId, r.Delimiter AS GroupId FROM GroupIdentifierTest r
This should make things easier
actually, there is not much you can do to populate the dataset
thinking about it
 
That's been my experience!
 
4:54 AM
nah
there is not much you can do
maybe a recursive cursor
but even so
or maybe create a separate temporary table
but it wouldn't make much sense
 
I've been getting pretty close with Sum() Over, but it's off on one row.
 
that can be a question to ask
going to get breakfast with the kids. catch you later
 
Cool. Thanks
 
 
3 hours later…
War
7:34 AM
yikes ... busy night!!!
questions at 5am here lol
 
8:19 AM
yeah I stopped at midnight!
also morning guys!
 
War
8:37 AM
mornin
 
9:03 AM
hi @War & @Shaneis
 
s'up @AndyK
 
War
9:22 AM
hey @AndyK
just reading some more hilarity from russia
I swear this guy just likes posting rants about stuff that works to be controversial
 
 
1 hour later…
10:42 AM
#lmao @War
not much @Shaneis, just dealing with the intern who's asking questions
at least, he's asking questions
 
@AndyK yup, that's the spirit :)
 
@War one thing though: Ukrainians hate to be called Russians
 
@AndyK ah...that's...that must have been fun to find that out :|
 
the vast majority of Ukrainians hates the Russian
I'm going for my lunch break
not really sure where did my time go
-_-
 
War
11:09 AM
@AndyK I'll make a point to call him that then ... regularly!!!
 
@War "helping international relations from day 1"
 
War
I do try
this guy is looking for a fight basically
he wants people to rant at him
look at his own testimonials page
 
12:05 PM
yawn
Trying to use this variant "ADQL"
(Basically minimal SQL with some coordinate functions)
Problem is, it doesn't support COALESCE at all
So I'll just have to post-process it myself
 
@LegionMammal978 how many calls to the COALESCE function are you looking at? More than 2? e.g. COALESCE(column1, column2, column3..., n)?
 
12:30 PM
Hi all
 
hey @Alex
 
Hey Shaneis
 
Hey everyone, might I bug you with a problem I got with a sql query i'm using?
 
@tcsh go for it
 
Ok so, I got a database that contains orders, with various details - including a price column and a date column in which I store the price of the order and the date it was added, respectively. So far I got orders for the following months: October 16, December 16, January 17, February 17 and March 17. Oct16 I got 6 orders, Nov16 I got 133, Dec16 I got 220, Jan17 I got 260, Feb17 I got 294 and March17 I got 391 orders.
I'm using this query
select t1.month, t1.year, t1.total, (t1.total / t2.total - 1) * 100 as variation
from (
select year(date) as year, month(date) as month, sum(price) as total
from orders
group by year(date), month(date)
) t1
join (
select year(date) as year, month(date) as month, sum(price) as total
from orders
group by year(date), month(date)
) t2
on t2.year = case when t1.month = 1 then t1.year - 1 else t1.year end and
t2.month = case when t1.month = 1 then 12 else t1.month - 1 end;
But it only returns this
the 6 orders from Oct16 aren't showing up
What could be wrong?
 
12:38 PM
before I go any further, have you tried this
select t1.month, t1.year, t1.total, (t1.total / t2.total - 1) * 100 as variation
from (
select year(date) as year, month(date) as month, sum(price) as total
from orders
group by year(date), month(date)
) t1
left join (
select year(date) as year, month(date) as month, sum(price) as total
from orders
group by year(date), month(date)
) t2
on t2.year = case when t1.month = 1 then t1.year - 1 else t1.year end and
t2.month = case when t1.month = 1 then 12 else t1.month - 1 end;
 
Just did, this is the result.
The hell was wrong with it? -_-
 
from the quick look of your code, you're taking away the month before right?
there's no month before Oct 2016 in your data
and you were using a JOIN, which is the same as an INNER JOIN.
meaning there has to be a match otherwise it gets removed from the results
I changed it to a LEFT JOIN which keeps the data from the left hand side table and returns NULL if there is no match on the right hand side table
 
Just read about left join and joins in general, i'm fairly new to sql so was having a hard time understanding
Thanks for the help ^_^
you insta-rocked it lol.
 
12:58 PM
@tcsh haha cheers! Best o'luck on your SQL journey
 
Great job, Shaneis!
 
cheers @Alex
I've had that problem when I started out, that's how I guessed
 
But it's so subtle
On SQL Server, Management Studio helps.... we can see the data on the tables and then realize what's missing
 
yeah but this was a great clue (t1.total / t2.total - 1) * 100
add to that the fact that he used a join
and you pretty much had the answer there
 
Silly question... what's the minus 1 doing in that code?
 
1:05 PM
it's to get the percentage I'd say
 
Yeah
 
prob easier to read like this ((t1.total / t2.total) - 1) * 100
 
Yup, calculating %
 
1:18 PM
So lemme get this straight, the difference between January 2017 and December 2016 in terms of earnings is 20%?
As in, 20% increase in Jan compared to Dec?
While in March 17 I've had a 30% increase in earnings compared to February 17?
 
1:31 PM
what db are you working on @tcsh?
 
MysQL
InnoDB
 
huh interesting, didn't know what it was
it's weird because when I run this
SELECT ((22558.0 / 27117.0) - 1) * 100
I get around 16%
-16.81233200 exactly
and that's because I'm an idiot and had them in the wrong order
SELECT ((27117.0 / 22558.0) - 1) * 100
20.21012500
 
hahaha
cheers mate!
 
@tcsh no worries, I need to get a coffee after that blunder :(
 
Go for it and enjoy :D
Just don't overdo it :))
 
1:42 PM
@tcsh CHALLENGE ACCEPTED!!!
 
1pa
Hello again! I'm trying to insert a lot of data from one file into a table and i'm using this command:
time cat results_table_file.txt | sed '1d; s/\\/\\\\/g' | psql -c "copy results(id, a, b, c, d) from stdout with delimiter '@'" database6
(each lines will be a row in my table)
The problem is that sometimes the rows have more fields, and i get this error: ERROR: extra data after last expected column, so how can i pass this lines and save them into a something like a error file?
 
hi @1pa good to see you again (during the day)
quick q, and I don't want to come across strong, but...
WHAT THE HELL LANGUAGE IS THAT?
:O
 
seems like Unix or something
 
@tcsh oh!
 
I could be wrong though
 
1:48 PM
huh, yeah don't know it
@tcsh you could be right also
 
that cat results_table_file.txt and the | in between them got me thinking of unix
 
1pa
i mix unix with postgres
 
there you go ;)
knew was on to something :D
 
@tcsh clap clap
 
1pa
This approach is so fast with a lot of data (millions)
 
1:50 PM
yup. So he's basically cat'ing the file contents, as in reading them (displaying on screen) really fast
then doing something (no idea what sed is)
 
hold on, getting that coffee
brb
 
then the postgres
and inserting, I assume.
Sorry - can't help since you lost me after the first |, after the cat =)
 
1pa
forget the sed part xD
@tcsh you are correct!
 
hey guys
 
make it easier and break them in to patterns?
or .. not the case?
 
1:52 PM
@War #rotfl
 
I'm thinking of grep and >> newfilename and so on..if I remember Unix correctly
:))
I'll shut up now lol
 
1pa
so i have a file something like this:
idnumber@a@b@c@d
...
but somethimes i have a extra column and i just want to ignore that xD
@tcsh humm probably i should try that but how can i make the program continue even after that error?
 
Edit the file first and just eliminate the column you wish to ignore?
Like using a regex approach or smth?
You can filter data in patterns using grep
cat otherfile | grep 'something'
Hence you can presumably 'edit' out that column while grepping
then using the new file to run your postgres
or whatever you're doing
cat otherfile | grep 'something' >> newfilenameoutput
I think it was..
You can read up on grep here
I honestly don't remember that much, It's been well over 15 years since I've used these commands ^_^
I'll let Shaneis step in buzzed on coffee, maybe he can help :)
 
1pa
Nice thank you! @tcsh i will read about that. I still here when @Shaneis return
 
kk, yw
 
2:18 PM
I'm back and buzzed on coffee @tcsh
but that doesn't change the fact that I don't know unix...
@1pa is there anyway to only select the first 4 rows before you try and insert them?
 
1pa
i don't know a lot about unix too but i will search and if i find the answer i'll let you guys know :)
 
You could always try editing the file using Notepad++ and CTRL+ALT entire rows out :D
or rather..columns, not rows.
 
1pa
@tcsh probably i will do that xD
 
@1pa if you do find out, make sure to let us know. that code is funny looking but interesting :)
 
1pa
sure @Shaneis thank you all ^^
 
2:25 PM
@1pa np, best o'luck
 
If you're still talking about time cat results_table_file.txt | sed '1d; s/\\/\\\\/g' | psql -c "copy results(id, a, b, c, d) from stdout with delimiter '@'" database6

Then you could do a sed before it... you could do something like:
cat results...txt | sed '1d; s/\\/\\\\/g' | sed 's/\(@.*\)[5]\(@.*\).*/\2/' > errors.txt
cat results...txt |sed '1d; s/\\/\\\\/g' | sed 's/\(@.*\)[5]\(@.*\).*/\1/' | plsql...
Not the most efficient way to do it. Also that sed might be off
but thats the gist of how I'd approach it
 
what's a sed?
 
hey @mkingsbu :) explain your wizardry please :)
 
is it like an STD? ^_^
2
 
@tcsh I think it's an old, old, wooden ship....
 
2:29 PM
sed is an unix application that does some kind of text substitution
 
oh..
 
cat puts your txt file into memory
then the | combines the commands
 
y
thanks for the sed part - I learn something everyday lol
what a weird name.
 
Yeah I have no idea if its an acronym for something
been around since the 80s
seems like a lot of people prefer PERL since it kind of supercedes a lot of its funcationality
but if you look at legacy code you'll see see sed and awk pretty frequently for text manipulation
So basically your first sed is doing a substitution
so 1d deletes the frist line then does something with slashes
s/ /g' is the format
the / / are dividers
g is global
so s is substitute
so it globally replaces \\ with \\\\
My sed, which may need some tweaking basically looks for groupings of @. The .* means any number of any character. So I believe what that will do is look for five patterns of @ followed by any number of other characters before another @. The \2 replaces everything in both groups with just the second group, which in this case is everything past the 6th column. Then the > error.txt sends all the results to the text file.

In the case of the former, it replaces both of the patterns with \1 which is just the first five columns.
 
@mkingsbu that, if I'm understanding it right, sounds exactly what he was looking for
cheers @mkingsbu!
 
2:34 PM
At least I think that's what it should do. There are different versions of sed and awk depending on OS. I worked at a place that had RHEL, Solaris, and AIX machines and each of them had different syntax :/
 
1pa
yay! @mkingsbu thank you very much!
 
War
@AndyK I think he's one of those classic troll types that gets a kick from simply winding communities of devs up
can't wait til he winds up the wrong dev who happens to be an awesome hacker
lol
 
Sure no problem! Bear in mind it will be pretty intensive processor wise though (well, could be). So if you're doing this frequently there's bound to be a better solution... I know you could do it in perl for example and may be able to do all of the text replacing in one command. But if you run this a few times a day then you won't notice the innefficiency at all
 
1pa
one more thing @mkingsbu and if i just want to delete the last @ if there are more than 4 ?
 
So like @text@test@test@text@?
 
War
2:37 PM
trim ?
 
@text@test@test@text@ -> @text@test@test@text
 
1pa
yap
 
War
string.Trim('@', @text@test@test@text@)
something like that
can't remember the exact way to call it ... params might be round the wrong way
 
If you're doing a sed already, I'd probably change it to:
 
1pa
@War i will check Thank you
 
2:38 PM
cat results...txt | sed '1d; s/\\/\\\\/g' | sed 's/\(@.*\)[4]\(@.*\).*/\2/' > errors.txt
cat results...txt |sed '1d; s/\\/\\\\/g' | sed 's/\(@.*\)[4]\(@.*\).*/\1/' | plsql...
 
Hi - quick question here about columns and syntax if someone can help?
 
The only difference is the [4] instead of [5]. I'm assuing you're on some kind of *nix box? You can test your manipulations by doing:

cat results...txt | sed 'blah'

And it will just show you the result of the output on the screen.
 
War
@1pa ah ok, its like this ...
var source = "@text@test@test@text@";
var result = source.TrimEnd(new[] { '@' });
 
you know with SQL Server coming to Linux, I should probably start learning this language...
 
War
or you can replace TrimEnd with just Trim to trim both ends of their @
oh wait ... im in SQL giving C# advice
 
2:41 PM
USE msdb
GO
SELECT
   j.[name] AS [Job Name],
   run_status = CASE h.run_status
   WHEN 0 THEN 'Failed'
   WHEN 1 THEN 'Succeeded'
   WHEN 2 THEN 'Retry'
   WHEN 3 THEN 'Canceled'
   WHEN 4 THEN 'In progress'
   END,
   h.run_date  AS [Last Run Date]  ,
   h.run_time AS [Last Run Time]
FROM sysjobhistory h
   INNER JOIN sysjobs j ON h.job_id = j.job_id
       WHERE j.enabled = 1 AND h.run_status = 0
       AND h.instance_id IN
       (SELECT MAX(h.instance_id)
           FROM sysjobhistory h GROUP BY (h.job_id))
Just wondering if someone can explain the use of j. and h. here?
 
yay! A SQL question! I'm back where I belong again!!!
 
even a link to something that explains how this works
 
War
@Ricky they are aliases for sets of data
 
1pa
@mkingsbu thank you i'm testing your code, and thank you @War i learnt something new!
 
War
@1pa np ... glad I could help :)
@Shaneis haha
 
2:43 PM
@War yup! would you rather say sysjobs.name or 'j.name` @Ricky
 
thanks War, so basically I need to go and read up on SQL aliases?
 
especially when you have a lot of tables
or need the same table twice!
 
ah ok , yes makes sense!
 
War
@Ricky it's like declaring a variable in other languages
 
War
2:43 PM
SELECT * FROM TableName x
x is a reference to that table
 
so essentially that query uses aliases because tables are being joined?
 
War
from there on out you can refer to anything in that table with just x.ColName
 
otherwise you wouldn't need it?
 
War
yeh basically
aliases help make SQL code a bit more readable
imagine writing some java or C# without any variables
 
yep indeed
thanks a lot, will head on and do some reading up on aliases then!
oh, since I'm here...
trying to convert the date in the output to something more readable
   h.run_date  AS [Last Run Date] SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY] ,
   h.run_time AS [Last Run Time]
it doesn't like that, I'm sure its the syntax order
 
2:51 PM
date_format() ?
 
@tcsh nah it's SQL Server @tcsh
 
oh nvm
 
if I run it I get multipart identifier errors
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "j.name" could not be bound.
 
means your table has lost it's alias, show us the code good sir @Ricky
 
most likely @War
 
3:09 PM
USE msdb
GO
SELECT
j.[name] AS [Job Name],
run_status = CASE h.run_status
WHEN 0 THEN 'Failed'
WHEN 1 THEN 'Succeeded'
WHEN 2 THEN 'Retry'
WHEN 3 THEN 'Canceled'
WHEN 4 THEN 'In progress'
END,
h.run_date AS [Last Run Date] ,
h.run_time AS [Last Run Time]
FROM sysjobhistory h
INNER JOIN sysjobs j ON h.job_id = j.job_id
WHERE j.enabled = 1 AND h.run_status = 0
AND h.instance_id IN
(SELECT MAX(h.instance_id)
FROM sysjobhistory h GROUP BY (h.job_id))

GO
Thats the code Shaneis
you can see the part where I tried to convert Last Run Date
 
no...that looks fine...are you getting the error from that? @Ricky
 
no that is fine
USE msdb
GO
SELECT
j.[name] AS [Job Name],
run_status = CASE h.run_status
WHEN 0 THEN 'Failed'
WHEN 1 THEN 'Succeeded'
WHEN 2 THEN 'Retry'
WHEN 3 THEN 'Canceled'
WHEN 4 THEN 'In progress'
END,
h.run_date AS [Last Run Date] SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY] ,
h.run_time AS [Last Run Time]
FROM sysjobhistory h
INNER JOIN sysjobs j ON h.job_id = j.job_id
WHERE j.enabled = 1 AND h.run_status = 0
AND h.instance_id IN
(SELECT MAX(h.instance_id)
FROM sysjobhistory h GROUP BY (h.job_id))
this gives me an error though
 
yup! Cause that is different :)
hold on
 
haha sorry, should have just posted the whole thing!
 
On SQL Server, is it possible to use COALESCE to skip a null parameter?
 
3:14 PM
try this @Ricky
SELECT
j.[name] AS [Job Name],
run_status = CASE h.run_status
WHEN 0 THEN 'Failed'
WHEN 1 THEN 'Succeeded'
WHEN 2 THEN 'Retry'
WHEN 3 THEN 'Canceled'
WHEN 4 THEN 'In progress'
END,
CONVERT(varchar(10), h.run_date, 103) AS [Last Run Date], -- SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY] ,
h.run_time AS [Last Run Time]
FROM sysjobhistory h
INNER JOIN sysjobs j ON h.job_id = j.job_id
WHERE j.enabled = 1 AND h.run_status = 0
AND h.instance_id IN
(SELECT MAX(h.instance_id)
FROM sysjobhistory h GROUP BY (h.job_id))
@Alex what do you mean by "skip" @Alex
 
So, something like this: p.State = coalesce(@State, p.State)
 
So I asked a question a few days ago and I'm realizing I didn't quite ask what had intended:

http://stackoverflow.com/questions/43079338/performing-a-subquery-using-values-from-a-column-in-oracle

I made a slight change to my accepted answer because of my typo:
select ce.start_date as dates, count(distinct c.customer_id)
from cust_emp ce join
customers c
on c.customer_id = ce.cust_id
where (ce.end_date > ce.start_date or ce.deleted_yn = false or ce.deleted_yn is null) and
(c.term_date > ce.start_date or c.term_date is null)
 
So it would treat that WHERE clause as optional
Only run it if the parameter has a value
 
COALESCE does the same as ISNULL, it just can do it with more than 2 inputs
if you can do it with ISNULL then you can do it with COALESCE
hope that helps, to be honest I'm not quite sure without seeing your code
 
That makes sense now. I'm using it wrong
 
3:17 PM
for those kind of queries I use IF statements to call different procedures or use sp_executesql with dynamic strings
 
Thanks Shaneis - are you getting a different date format?

I'm still getting: 20170330
I'm looking it to be 30/03/2017 ... UK style
 
You can't do = COALESCE(). What if all values are null?
Null check requires is not =
 
sorry @Ricky, forgot that msdb stores it as a weird int
USE msdb
GO
SELECT
j.[name] AS [Job Name],
run_status = CASE h.run_status
WHEN 0 THEN 'Failed'
WHEN 1 THEN 'Succeeded'
WHEN 2 THEN 'Retry'
WHEN 3 THEN 'Canceled'
WHEN 4 THEN 'In progress'
END,
CONVERT(varchar(10), CAST(CAST(h.run_date AS varchar(8)) AS date), 103) AS [Last Run Date], -- SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY] ,
h.run_time AS [Last Run Time]
FROM sysjobhistory h
INNER JOIN sysjobs j ON h.job_id = j.job_id
WHERE j.enabled = 1 AND h.run_status = 0
AND h.instance_id IN
@Alex hmmm you got a quick repro @Alex
 
 p.State = coalesce(@State, p.State)
That in a WHERE clause. If the param is null and p.State is null, what the heck would it do?
 
Awesome , thanks Shaneis. I'll have a go at the time one myself now
 
3:22 PM
@Ricky best o'luck
@Alex depends, if it doesn't match, do you want to return everything or nothing? @Alex
 
return everything
 
it's not sargeable but...
coalesce(p.State, 0) = coalesce(@State, p.State, 0)
 
Ahhhh
Nice!
 
not really :( but sometimes you have to get down and dirty...
 
What the heck!
If it works and it's dirty, it still works :)
You come back later and refactor
 
3:35 PM
getting a conversion error :-(
CONVERT(varchar(4), CAST(CAST(h.run_time AS nvarchar(4)) AS time), 8) AS [Last Run Time]
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
 
@Ricky the joys of having data in the wrong data type
 
yep
 
cheers Microsoft, doing it yourself when you give out to us about it...
 
even in the msdb, weird
wondering why run_time is an int rather than date/time
 
@Ricky because it was how SQL Agent was set up to read and SQL Agent reads from those tables...fun times
hold on and I check something
 
3:40 PM
yeah having to type 30000 for a time when setting up a job...
 
@Ricky speaking of laziness, i was too lazy to write this out so I just gutted a function we have here for it
ISNULL(NULLIF(CONVERT(VARCHAR, CONVERT(INT,SUBSTRING(RIGHT(REPLICATE('0',24) + CONVERT(VARCHAR(24),h.run_time), 24), 1, 20)) / 24 ),0) + '.', '') +
				--CONVERT(VARCHAR, CONVERT(INT,SUBSTRING(@duration, 1, 20)) / 24 ) + 'd ' +
				RIGHT('00' + CONVERT(VARCHAR, CONVERT(INT,SUBSTRING(RIGHT(REPLICATE('0',24) + CONVERT(VARCHAR(24),h.run_time), 24), 1, 20)) % 24 ), 2) + ':' +
				SUBSTRING( RIGHT(REPLICATE('0',24) + CONVERT(VARCHAR(24),h.run_time), 24), 21, 2) + ':' +
				SUBSTRING( RIGHT(REPLICATE('0',24) + CONVERT(VARCHAR(24),h.run_time), 24), 23, 2),
throw that in instead of CONVERT(varchar(4), CAST(CAST(h.run_time AS nvarchar(4)) AS time), 8)
 
haha wow thats a mouthful
works though, awesome
 
@Ricky no worries, on the condition that you never say those two sentences again! I'm very immature and it took all my willpower to not make a joke there
 
haha it was a one off ;-)
thanks for all the help
 
no worries man, you're welcome here anytime
 
4:22 PM
heading off, tty later guys
 
4:44 PM
See ya, Shaneis
 
 
3 hours later…
7:36 PM
Hey all
 
7:50 PM
s'up @ChristopherJ.Grace
 
8:13 PM
Been slammed this afternoon
Hey @ChristopherJ.Grace, what's going on?
 
9:07 PM
@Shaneis - you around? :-)
 
yeah for the next 20 mins at least
whats up @tcsh?
 
Got an sql mystery for you
if you're up for it :-)
 
ha! Stop trying to push my buttons and just say it :)
 
^_^
I got the following code in my Delphi application, and it's subsequent sql query
procedure TForm2.actMemo1Execute(Sender: TObject);
begin
dbmodule.Memo1Query.Close;
Memo1.Clear;

dbmodule.Memo1Query.SQL.BeginUpdate;
try
dbmodule.Memo1Query.SQL.Add('select date_format(data, ''%M-%Y'') as df, sum(pret) as UV');
dbmodule.Memo1Query.SQL.Add('from arhivalux');
dbmodule.Memo1Query.SQL.Add('where statistica=''UV''');
dbmodule.Memo1Query.SQL.Add('group by statistica, year(data), month(data)');
finally
dbmodule.Memo1Query.SQL.EndUpdate;
end;

dbmodule.Memo1Query.Open;
try
while not dbmodule.Memo1Query.Eof do
When i push the button that runs this code
This happens
If I push the button again, it gives the following error
Now, the values itself are fine, the query works. Problem is I have to close and reopen the application entirely for the button to work on 2nd click. Can't figure out what the sql syntax error is in the sql query i'm using. I've been starring at it for hrs
 
I'm not surprised, it's way too generic
it could be anything
I'd guess that you sql is getting cut off half way through
don't know why though
I don't know Delphi :(
 
9:12 PM
But the query itself is written ok?
dbmodule.Memo1Query.SQL.Add('select date_format(data, ''%M-%Y'') as df, sum(pret) as UV');
dbmodule.Memo1Query.SQL.Add('from arhivalux');
dbmodule.Memo1Query.SQL.Add('where statistica=''UV''');
dbmodule.Memo1Query.SQL.Add('group by statistica, year(data), month(data)');
this part :D
data is a date field (timestamp)
pret is a price field (int)
 
Yeah, I don't think you need to group by statistica cause you're where clause only shows 1...
 
statistica is the name of a field that holds names, basically categories (UV, Print, etc)
 
yeah but all it's going to show is 'UV', no?
 
In the 1st memo, yes
in the 2nd, another similar query will run
which will show the same things but for a different statistica value
Namely, Print
get it?
Statistica is the name of a field which basically holds a couple of category names - for statistical purposes. So every order is assigned one of these names
in the 1st memo I'm showing earnings for just the ones assigned to UV
the 2nd memo, the ones assigned to Print
and so on
 
yeah I think so, it seems valid syntax as much as I know MySQL
 
9:17 PM
Gah, well at least that seems fine. I'll keep at it!
thanks for the effort, hope you won't need another coffee now ^_^
 
haha nah!
too late, I'll be online again in 20 if you need something else
 
I'll let you know, I'm about to start adding some statistical stuff to the app so I'll surely hit a wall in terms of sql lol
 
9:45 PM
Hey guys. It's going to be dark soon here. Time to get to work.
I checked out your NTILE solution Alan.
 
haha you mean time to get to sleep no?
 
Not for me. I'm on the 2-12 shift
Looks like you are too.
 
meh getting ready for the weekend, holiday time at home
 
Good for you.
That solution from yesterday worked, but there's still another similar problem.
Got dinged a point. I wonder why.
NTILE will not work. The distribution of the group boundaries varies.
 
eh no idea, unless they leave a comment it's impossible to know
so wwait, does 1 mark the end of a boundary?
 
9:55 PM
Exactly
It is the last row in the group
Thinking out loud, maybe it would be an easier problem if I could make it the row in the group.
the first row that is.
 
03:00 - 22:0022:00 - 23:00

« first day (1777 days earlier)      last day (2541 days later) »