D DeerBear Member Licensed User Longtime User Aug 23, 2014 #1 Hello! I'd like to do what is written in the subject in a SQLite query. Does anybody know of a way to do it? I've googled "android how to return a fixed string in a sqlite query" but I can't see any results (not even SO) about that... is it possible nobody's needed this? How do you solve this kind of issue? Kind Regards, A
Hello! I'd like to do what is written in the subject in a SQLite query. Does anybody know of a way to do it? I've googled "android how to return a fixed string in a sqlite query" but I can't see any results (not even SO) about that... is it possible nobody's needed this? How do you solve this kind of issue? Kind Regards, A
S sorex Expert Licensed User Longtime User Aug 23, 2014 #2 other database have a CAST command to get the job done, not sure if SQLite has this. (especially usefull when concatenating a string with number, not requires for just text) CAST('Total' as varchar(5)) as Total Upvote 0
other database have a CAST command to get the job done, not sure if SQLite has this. (especially usefull when concatenating a string with number, not requires for just text) CAST('Total' as varchar(5)) as Total
D DeerBear Member Licensed User Longtime User Aug 23, 2014 #3 sorex said: other database have a CAST command to get the job done, not sure if SQLite has this. (especially usefull when concatenating a string with number, not requires for just text) CAST('Total' as varchar(5)) as Total Click to expand... Many also just allow the syntax shown in the subject A Upvote 0
sorex said: other database have a CAST command to get the job done, not sure if SQLite has this. (especially usefull when concatenating a string with number, not requires for just text) CAST('Total' as varchar(5)) as Total Click to expand... Many also just allow the syntax shown in the subject A
M Mahares Expert Licensed User Longtime User Aug 23, 2014 #5 Are you looking for something like this where you assign your expression to a variable and include it in the query: Code: Dim strVar As String="TOTAL" txt="SELECT '" & strVar & "' AS DeerBear ,SUM(CODE) as SCODE FROM tblChemicals GROUP BY RANK " Cursor1= SQL1.ExecQuery(txt) Cursor1.position=8 Log(Cursor1.GetString("DeerBear") & " " & Cursor1.GetString("SCODE")) Upvote 0
Are you looking for something like this where you assign your expression to a variable and include it in the query: Code: Dim strVar As String="TOTAL" txt="SELECT '" & strVar & "' AS DeerBear ,SUM(CODE) as SCODE FROM tblChemicals GROUP BY RANK " Cursor1= SQL1.ExecQuery(txt) Cursor1.position=8 Log(Cursor1.GetString("DeerBear") & " " & Cursor1.GetString("SCODE"))
S sorex Expert Licensed User Longtime User Aug 23, 2014 #6 no, it's the select 'xxx' as fieldname that doesn't seem to work. Edit: I re-read the initial post and he doesn't even say that it didn't work, you never know when you don't try it I guess. Upvote 0
no, it's the select 'xxx' as fieldname that doesn't seem to work. Edit: I re-read the initial post and he doesn't even say that it didn't work, you never know when you don't try it I guess.
K keirS Well-Known Member Licensed User Longtime User Aug 23, 2014 #7 It does work exactly as the OP put in the subject line Upvote 0
udg Expert Licensed User Longtime User Aug 24, 2014 #8 Hi all, I don't use sqlite but what about something like the following? Code: DECLARE @MyTotal NCHAR(5); SET @MyTotal = 'Total'; SELECT @MyTotal, SUM(MyValue) FROM... And a brief look at Sqlite doc showed a quote(X) function which should return X literal or even coalesce(X,Y,.) function that returns first not null parameter. Hope some of the above may help you. Umberto Upvote 0
Hi all, I don't use sqlite but what about something like the following? Code: DECLARE @MyTotal NCHAR(5); SET @MyTotal = 'Total'; SELECT @MyTotal, SUM(MyValue) FROM... And a brief look at Sqlite doc showed a quote(X) function which should return X literal or even coalesce(X,Y,.) function that returns first not null parameter. Hope some of the above may help you. Umberto
D DeerBear Member Licensed User Longtime User Aug 24, 2014 #9 Groan... I re-typed it for the post... guess what? Typo... A Upvote 0
Jaames Active Member Licensed User Longtime User Aug 24, 2014 #10 Isn't it "SELECT SUM(fieldtosum) AS Total FROM someTable" With sql executesingleresult ? Upvote 0
S sorex Expert Licensed User Longtime User Aug 24, 2014 #11 no, it seems he wants the first field to output 'total'. it doesn't make much sense actually, if you know that field is always 'Total' I don't see a reason to add it to the restult as you know the result in advance. Upvote 0
no, it seems he wants the first field to output 'total'. it doesn't make much sense actually, if you know that field is always 'Total' I don't see a reason to add it to the restult as you know the result in advance.
udg Expert Licensed User Longtime User Aug 24, 2014 #12 Hi, testing on http://sqlfiddle.com with Code: SELECT 'Total', * FROM MYTABLE; The output was: 'Total' ID, NAME Total 1, Joe Total 2, John While with code similar to yours, I have Code: SELECT 'Total', SUM(ID) FROM MYTABLE; returns: 'Total' SUM(ID) Total 3 Regards, Umberto Upvote 0
Hi, testing on http://sqlfiddle.com with Code: SELECT 'Total', * FROM MYTABLE; The output was: 'Total' ID, NAME Total 1, Joe Total 2, John While with code similar to yours, I have Code: SELECT 'Total', SUM(ID) FROM MYTABLE; returns: 'Total' SUM(ID) Total 3 Regards, Umberto
D DeerBear Member Licensed User Longtime User Aug 25, 2014 #13 sorex said: no, it seems he wants the first field to output 'total'. it doesn't make much sense actually, if you know that field is always 'Total' I don't see a reason to add it to the restult as you know the result in advance. Click to expand... Hi! It does make sense if you want to take advantage of ExecuteListView and have a 2 lines items where the first line says "Total" and the second shows you that very total Upvote 0
sorex said: no, it seems he wants the first field to output 'total'. it doesn't make much sense actually, if you know that field is always 'Total' I don't see a reason to add it to the restult as you know the result in advance. Click to expand... Hi! It does make sense if you want to take advantage of ExecuteListView and have a 2 lines items where the first line says "Total" and the second shows you that very total