eapen ittiyera
eapen ittiyera

Reputation: 55

how to write a sql query in db2 on ibm_cloud

I have a table called PEOPLEINFO that has the following columns:

1. Studentname
2. Grade
3. Telnum

When I run an sql query on Db2 on ibm_cloud to fetch all the StudentName using the query:

Select Studentname from PEOPLEINFO

I get the following error:

"STUDENTNAME" is not valid in the context where it is used.. SQLCODE=-206, >SQLSTATE=42703, DRIVER=4.24.92

But if I run the query:

Select * from PEOPLEINFO

it works just fine.

What is the correct way to access the values of a particular column using sql on db2? I'm fairly new to ibm_cloud, so do let me know where I'm going wrong.

EDIT: Table was created by uploading a csv file to db2. It then auto generated the database using the csv file.

Upvotes: 0

Views: 574

Answers (1)

data_henrik
data_henrik

Reputation: 17176

Db2 (and SQL) identifiers can be given without quotes. In that case everything is uppercased. If you or your tool used double quotes when creating the table, then you need to refer to the objects with exactly the same names. Thus, you would need to use double quotes around the name and write it in the same way.

Check out the Db2 documentation on identifiers for details.

Henrik, henrik, HenRik => HENRIK

"Henrik" != "henrik" != "HenRIK" != "HENRIK"

Upvotes: 4

Related Questions