473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VALUES statement

Hi!

With VALUES you can do something like:
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER, NUMBER)
which will give you:
LETTER NUMBER
------ ------
A 1
B 2
C 2

It there some way with VALUES that would give me:
LETTER NUMBER
------ ------

So no results, empty result set?
So SELECT COUNT(*) FROM VALUES..... returns 0.

Best regards,
Kovi
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Mar 9 '07 #1
13 38165
On Mar 9, 1:31 pm, Gregor Kovač <gregor.ko...@m ikropis.siwrote :
Hi!

With VALUES you can do something like:
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER, NUMBER)
which will give you:
LETTER NUMBER
------ ------
A 1
B 2
C 2

It there some way with VALUES that would give me:
LETTER NUMBER
------ ------
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER,
NUMBER) where 1=0

/Lennart

[....]

Mar 9 '07 #2
Lennart wrote:
On Mar 9, 1:31 pm, Gregor Kovač <gregor.ko...@m ikropis.siwrote :
>Hi!

With VALUES you can do something like:
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER,
NUMBER) which will give you:
LETTER NUMBER
------ ------
A 1
B 2
C 2

It there some way with VALUES that would give me:
LETTER NUMBER
------ ------

SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER,
NUMBER) where 1=0

/Lennart

[....]
Yes, this could work, but the problem is that VALUES .... gets generated,
and the where clause not.
Let me clearify. :)))
I'm using VALUES statement to generate an SQL statement using values in a
table in a GUI mask. So the application that generates this query must be
aware that the table is empty and generate appropriate SQL.
In the line of:
SELECT * FROM (VALUES ('a', 1) EXCEPT ALL VALUES ('b', 2)) AS TEMP(LETTER,
NUMBER)

Best regards,
Kovi

--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Mar 9 '07 #3
What about this?
SELECT * FROM (VALUES (NULL, NULL), -- Fixed
(1, 'a'), (2, 'b'), ... -- generated
) AS X(c1, c2) WHERE NOT (c1 IS NULL AND c2 IS NULL) -fixed

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 9 '07 #4
Serge Rielau wrote:
SELECT * FROM (VALUES (NULL, NULL), * * *-- Fixed
(1, 'a'), (2, 'b'), ... -- generated
) AS X(c1, c2) WHERE NOT (c1 IS NULL AND c2 IS NULL)
Hi!

This wouldn't work since the part (1, 'a'), (2, 'b'), ... will not be
generated (the GUI table is empty, remember ?) and SELECT * FROM (VALUES
(NULL, NULL)) AS X(c1, c2) WHERE NOT (c1 IS NULL AND c2 IS NULL) yields
[Error Code: -584, SQL State: 42608] Invalid use of NULL or DEFAULT.

I like the EXCEPT ALL more. :))))

Best regards,
Kovi
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Mar 9 '07 #5
On Mar 9, 2:25 pm, Gregor Kovač <gregor.ko...@m ikropis.siwrote :
Lennart wrote:
On Mar 9, 1:31 pm, Gregor Kovač <gregor.ko...@m ikropis.siwrote :
Hi!
With VALUES you can do something like:
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER,
NUMBER) which will give you:
LETTER NUMBER
------ ------
A 1
B 2
C 2
It there some way with VALUES that would give me:
LETTER NUMBER
------ ------
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER,
NUMBER) where 1=0
/Lennart
[....]

Yes, this could work, but the problem is that VALUES .... gets generated,
and the where clause not.
I don't understand. Assuming you get this as input:

String s = "SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER)";

couldn't you just add the where clause as:

s = s + " where 1=0";

before firing off the query?
Let me clearify. :)))
I'm using VALUES statement to generate an SQL statement using values in a
table in a GUI mask. So the application that generates this query must be
aware that the table is empty and generate appropriate SQL.
In the line of:
SELECT * FROM (VALUES ('a', 1) EXCEPT ALL VALUES ('b', 2)) AS TEMP(LETTER,
NUMBER)
This will not generate an empty result set. Did you mean

SELECT * FROM (VALUES ('a', 1) INTERSECT VALUES ('b', 2)) AS
TEMP(LETTER, NUMBER) ?

But how do you assure that there are no duplicates (i.e. the
intersection is truly empty)?

/Lennart

Mar 9 '07 #6
Lennart wrote:
On Mar 9, 2:25 pm, Gregor Kovač <gregor.ko...@m ikropis.siwrote :
>Lennart wrote:
On Mar 9, 1:31 pm, Gregor Kovač <gregor.ko...@m ikropis.siwrote :
Hi!
>With VALUES you can do something like:
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER,
NUMBER) which will give you:
LETTER NUMBER
------ ------
A 1
B 2
C 2
>It there some way with VALUES that would give me:
LETTER NUMBER
------ ------
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER,
NUMBER) where 1=0
/Lennart
[....]

Yes, this could work, but the problem is that VALUES .... gets generated,
and the where clause not.

I don't understand. Assuming you get this as input:

String s = "SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER)";

couldn't you just add the where clause as:

s = s + " where 1=0";

before firing off the query?
Because the query itself is written by the user. And if the user does:
SELECT * FROM {GET_TABLE(GUI_ TABLE)} WHERE LETTER = 'A'
then the application would generate
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER, NUMBER)
WHERE 1=0 WHERE LETTER = 'A'
which is an invalid SQL. Do you agree?
>Let me clearify. :)))
I'm using VALUES statement to generate an SQL statement using values in a
table in a GUI mask. So the application that generates this query must be
aware that the table is empty and generate appropriate SQL.
In the line of:
SELECT * FROM (VALUES ('a', 1) EXCEPT ALL VALUES ('b', 2)) AS
TEMP(LETTER, NUMBER)

This will not generate an empty result set. Did you mean

SELECT * FROM (VALUES ('a', 1) INTERSECT VALUES ('b', 2)) AS
TEMP(LETTER, NUMBER) ?

But how do you assure that there are no duplicates (i.e. the
intersection is truly empty)?

/Lennart
ups.. :)
I meant
SELECT * FROM (VALUES ('a', 1) EXCEPT ALL VALUES ('a', 1)) AS TEMP(LETTER,
NUMBER)

Best regards,
Kovi
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Mar 9 '07 #7
Gregor Kovač wrote:
Serge Rielau wrote:
>SELECT * FROM (VALUES (NULL, NULL), -- Fixed
(1, 'a'), (2, 'b'), ... -- generated
) AS X(c1, c2) WHERE NOT (c1 IS NULL AND c2 IS NULL)

Hi!

This wouldn't work since the part (1, 'a'), (2, 'b'), ... will not be
generated (the GUI table is empty, remember ?)
and SELECT * FROM (VALUES
(NULL, NULL)) AS X(c1, c2) WHERE NOT (c1 IS NULL AND c2 IS NULL) yields
[Error Code: -584, SQL State: 42608] Invalid use of NULL or DEFAULT.
All to need is to cast the NULLs.
(CAST(NULL AS INT), CAST(NULL AS VARCHAR(10)), ...
I like the EXCEPT ALL more. :))))
Anything that works...

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 9 '07 #8
On Mar 9, 3:36 pm, Gregor Kovač <gregor.ko...@m ikropis.siwrote :
[...]
Because the query itself is written by the user. And if the user does:
SELECT * FROM {GET_TABLE(GUI_ TABLE)} WHERE LETTER = 'A'
then the application would generate
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER, NUMBER)
WHERE 1=0 WHERE LETTER = 'A'
which is an invalid SQL. Do you agree?
Absolutely. How about (I'm using python):

if (s.find('WHERE' ) 0):
s = s + ' AND '
else:
s = s + ' WHERE '
s = s + '1=0'

Test:

[lelle@53dbd181 lelle]$ cat aa.py
#!/usr/bin/python

s1 = "SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER)"
s2 = "SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER) WHERE LETTER = 'A'"
for s in [ s1, s2 ]:
print 'Input: %s' % (s)
if (s.find('WHERE' ) 0):
s = s + ' AND '
else:
s = s + ' WHERE '
s = s + '1=0'
print 'Result: %s' % (s)
>>>>
[lelle@53dbd181 lelle]$ ./aa.py
Input: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER)
Result: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER) WHERE 1=0
Input: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER) WHERE LETTER = 'A'
Result: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER) WHERE LETTER = 'A' AND 1=0
/Lennart

[...]

Mar 9 '07 #9
Lennart wrote:
On Mar 9, 3:36 pm, Gregor Kovač <gregor.ko...@m ikropis.siwrote :
[...]
>Because the query itself is written by the user. And if the user does:
SELECT * FROM {GET_TABLE(GUI_ TABLE)} WHERE LETTER = 'A'
then the application would generate
SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER,
NUMBER) WHERE 1=0 WHERE LETTER = 'A'
which is an invalid SQL. Do you agree?

Absolutely. How about (I'm using python):

if (s.find('WHERE' ) 0):
s = s + ' AND '
else:
s = s + ' WHERE '
s = s + '1=0'

Test:

[lelle@53dbd181 lelle]$ cat aa.py
#!/usr/bin/python

s1 = "SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER)"
s2 = "SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER) WHERE LETTER = 'A'"
for s in [ s1, s2 ]:
print 'Input: %s' % (s)
if (s.find('WHERE' ) 0):
s = s + ' AND '
else:
s = s + ' WHERE '
s = s + '1=0'
print 'Result: %s' % (s)
>>>>>

[lelle@53dbd181 lelle]$ ./aa.py
Input: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER)
Result: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER) WHERE 1=0
Input: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER) WHERE LETTER = 'A'
Result: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS
TEMP(LETTER, NUMBER) WHERE LETTER = 'A' AND 1=0
/Lennart

[...]
Sounds OK, but :))) (there is always a but :)) )
when the GUI table is empty then the part ('A', 1), ('B', 2), ('C', 2) can
only be made up.

Best regards,
Kovi

--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Mar 9 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
17093
by: Matt | last post by:
When the ASP statement end with a _ character, then the next line cannot have comment ' character. Is that correct? Since I encountered the following error: Microsoft VBScript compilation (0x800A0400) Expected statement sqlStmt = "insert into TimeSlot (WeekDay, BeginTime, EndTime) VALUES (" _ ' & 2 & "," _ & beginhour & "," _
1
7124
by: mirth | last post by:
I would like to update a decimal column in a temporary table based on a set of Glcodes from another table. I search for a set of codes and then want to sum the value for each row matching the Glcodes. The problem is I keep getting multiple rows returned errors. "Subquery returned more than 1 value. This is not permitted when the subquery...
22
1731
by: Alan | last post by:
I have many OR in the if statement, any method to simplify? if (val == 5 | val == 9 | val == 34 | val == 111 | val == 131 | .......) // .... thank you
7
11421
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And #11/2/2003# And VehicleID='00000000' And BattID='LKO500HF'. I need to use the records returned to populate text boxes, but the data requires further...
9
3334
by: khan | last post by:
on sale report I want to make a check if customer doesnot pay full amount then his dues go in to his account recieveable table. I am trying this in vba and when I complie it on RunSQL it gives me error "wrong number of argments", Can any one help plzzz If Val(Me.Due) > 0 Then DoCmd.RunSQL "Insert into (customerID,reciept#,amountDue)...
15
2786
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
2
2286
by: Keith | last post by:
Good Afternoon, New to .Net. I am trying to pass date/time values to a MS Access query depending on what value is selected from a dropdown list box (January, February, etc). I have declared those values as date datatypes and assigned their values with the # signs in front and back. When I click the submit I get the following error message: ...
41
2730
by: Gary Wessle | last post by:
Hi often I need to read numbers and only keep the highest or lowest. so I do something like int uLimit = 0; int lLimit = 999999999999; //hoping the compiler will not complain uLimit = val_read uLimit ? val_read : uLimit; lLimit = val_read < lLimit ? val_read : lLimit;
3
7690
by: Joshepmichel | last post by:
Please to help me to following problem I want to do this 1. create Table Name MEMBER on the Database Name "mytestdb", 2. Add the Values to the Table through the Key board Inputs during running the My Java Application.; Therefore I used this following codes, It Consists the seperate parts for the Raede and Member Class for the purposely I...
0
7502
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
744
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.