sql attribute name - sql

I have a table with five columns and there is an attribute with the name NoOfCreditCards. This attribute's data type is varchar with length 2. When the table is shown in the SQL command line the name of the NoOfCreditCards column appears only as No, the rest part of the name does not appear. I have tried to use "set lin" with different sizes, but it did not work. How can i resolve this issue?

You have to name the columns in your select statement.
Something like this:
SELECT NoOfCreditCards "NoOfCreditCards"
FROM TABLE
WHERE ...;

Related

To fetch the datatype of a column, present in the custom type

I have a table which has two varchar columns where the raw data is stored. This raw data contains value and the field name. Field name is like my_cursor.attribute1. This cursor is of the data type (my_custompackage.custom_data_type).
Now, I need to get the data type of the column present in the custom_data_type.
This is wrong, but to give an idea it's something like
my_custompackage.custom_data_type.attribute13
But so far, I couldn't achieve anything. I have tried taking the value into a separate variable. Like `
select field_name into temp_variable from dual;
Then
select dump(temp_variable) into my_data_type
but it didn't work and I was getting the string value. So, could you please tell me how to proceed with this?

Oracle query in jasper not returnig data where data type is varchar?

I am running below query in Jasper (using Oracle DB) but returning empty because the data type of the name is varchar but it is returning if I select the column which has number or date as a data type.
select name from student_data;
attached is the screenshot of the property. and below is the query
select name, date_of_birth from student_data. i will have data for date_of_birth but name column is empty.
enter image description here
Jaspersoft-Studio and also the older version iReport have the Problem, that they are implementet with the wrong datatype. for example
DB column: ID(int)
iReport_FIELD: ID(BigDecimal)
But you should be able to simply change the Datatype of the Field.
Go to the "Fields" part of your Navigation-Window and select the Field with the wrong Datatype
On the Property-Window you can see one of The Properties of the Fiels is "Field Class", There you can change the Class of your name Field.

Select columns from table in schema different than public

In my PostgreSQL database I have table that is inside import schema. When I want to get all data from the column I do:
select * from import.master_plan
This query works fine. But when I try to for example get only title column values:
select import.master_plan.title from import.master_plan;
it returns:
ERROR: column master_plan.title does not exist
LINE 1: select import.master_plan.title from import.master_plan;
^
HINT: Perhaps you meant to reference the column "master_plan.  title".
I've also tried:
select title from import.master_plan;
but this also not works. I'm using PostgreSQL 10. How can I fix that?
I would suggest that you use a table alias instead:
select mp.title
from import.master_plan mp;
This is much easier to read and to type.
Judging from the error message, though, the name seems to have leading spaces. Something like:
select mp." title"
from import.master_plan mp;
might work. If this is the case, alter the table and rename the column.

Converting data type on SQL Server View Creation

I'm fairly new to SQL, and I'm having some problems converting a data type of Guid to String when creating my View. After having a look into the issue I'm not sure why the following statement is throwing the error:
Create View or Function failed because no column name was specified for column 2.
Statement:
CREATE VIEW CustomerContactView
AS
SELECT [Id]
,CAST([Guid] AS NVARCHAR(100))
,[ContactGuid]
,[MethodId]
,[Details]
,[OutcomeId]
,[ActionRequired]
,[IsValid]
FROM [Main].[dbo].[Customer_ContactLog]
Any help is greatly appreciated, Thanks
You just need to give a new name for that column that will be used when selecting from the view:
CREATE VIEW CustomerContactView
AS
SELECT [Id]
,CAST([Guid] AS NVARCHAR(100)) AS Guid
,[ContactGuid]
,[MethodId]
,[Details]
,[OutcomeId]
,[ActionRequired]
,[IsValid]
FROM [Main].[dbo].[Customer_ContactLog]
This is because the value in that column is calculated dynamically and is not related to the value in table. A computed column is a virtual column that is not physically stored in the table therefore the DBMS cannot use the original column name from a table.
In a view, when you apply a function or otherwise manipulate a column, concatenate multiple columns, anything like that, you need to give that column an alias:
CAST([Guid] AS NVARCHAR(100)) AS <some clever alias goes here>.
It's as exactly as the error says: you're not specifying a column name for the second column in your view. If you run that SELECT as-is, you'll see the following for column names:
ID (No column name) ContactGuid... etc.
Change it to this:
CREATE VIEW CustomerContactView
AS
SELECT [Id]
,CAST([Guid] AS NVARCHAR(100)) [Guid]
,[ContactGuid]
,[MethodId]
,[Details]
,[OutcomeId]
,[ActionRequired]
,[IsValid]
FROM [Main].[dbo].[Customer_ContactLog]

Does the result of SELECT MAX([ColumnName]) have a column name?

Does the result of SELECT MAX([ColumnName]) have a column name? I know the result is a view of only one record and I'd thought this view has the original column name as the result column name?
It does not but you can give it one
SELECT MAX([ColumnName]) AS MaxName
If you think about it you will see why your assumption is wrong. What if the code was like this:
SELECT MAX([ColumnName]), MIN([ColumnName])
Which of the two will take the name of the column?
By default no, there is no particular column name. If you specify an alias it will have.
SELECT MAX([ColumnName]) as [max_value_column_name]