Oracle SQL Plus not all table columns displayed - sql

I've created this table :
CREATE TABLE PRODUCT (
P_CODE CHAR(8),
P_DESCRIPT CHAR(200),
P_INDATE CHAR(20),
P_ONHAND INTEGER,
P_MIN INTEGER,
P_PRICE NUMBER,
P_DISCOUNT NUMBER,
V_CODE CHAR(5)
);
And I've inserted the following data in the table:
INSERT INTO PRODUCT VALUES ('11QER/31','Power painter, 15 psi, 3-nozzle','12/2/96',8,5,109.99,0.00,25595);
INSERT INTO PRODUCT VALUES ('13-Q2/P2','7.25-in. pwr. Saw blade','11/12/96',32,15,14.99,0.05,21344);
INSERT INTO PRODUCT VALUES ('14-Q1/L3','9.00-in. pwr. Saw blade','11/12/96',18,12,17.49,0.00,21344);
INSERT INTO PRODUCT VALUES ('156-QQ2','Hrd. Cloth, 1/4-in., 2x50','8/14/96',15,8,39.95,0.00,23119);
INSERT INTO PRODUCT VALUES ('1558-QW1','Hrd. Cloth, 1/2-in., 3x50','8/14/96',23,5,43.99,0.00,23119);
INSERT INTO PRODUCT VALUES ('2232/QTY','B&D jigsaw, 12-in, blade','10/29/96',8,5,109.92,0.05,24288);
INSERT INTO PRODUCT VALUES ('2232/QWE','B&D jigsaw, 8-in, blade','9/23/96',6,5,99.87,0.05,24288);
INSERT INTO PRODUCT VALUES ('2238/QPD','B&D cordless drill, 1/2-in.','10/19/96',12,5,38.95,0.05,25595);
INSERT INTO PRODUCT VALUES ('23109-HB','Claw hammer','11/19/96',23,10,9.95,0.10,21225);
INSERT INTO PRODUCT VALUES ('23114-AA','Sledge hammer, 12 lb.','12/1/96',8,5,14.40,0.05,null);
INSERT INTO PRODUCT VALUES ('54778-2T','Rat-tail file, 1/8-in. fine','6/14/96',43,20,4.99,0.00,'21344');
INSERT INTO PRODUCT VALUES ('89-WRE-Q','Hicut chain saw, 16 in.','7/6/96',11,5,256.99,0.05,'24288');
INSERT INTO PRODUCT VALUES ('PVC23DAT','PVC pipe, 3.5-in., 8-ft','12/19/96',188,75,5.87,0.00,null);
INSERT INTO PRODUCT VALUES ('SM-18277','1.25-in. metal screw, 25','11/28/96',172,75,6.99,0.00,'21225');
INSERT INTO PRODUCT VALUES ('SW-23116','2.5-in. wd. screw, 50','9/23/96',237,100,8.45,0.00,'21231');
INSERT INTO PRODUCT VALUES ('WR3/TT3','Steel matting, 4''x8''x1/6", .5" mesh','11/16/96',18,5,119.95,0.10,'25595');
INSERT INTO PRODUCT VALUES ('11QER/31','Power painter, 15 psi, 3-nozzle','12/2/96',8,5,109.99,0.00,25595);
INSERT INTO PRODUCT VALUES ('13-Q2/P2','7.25-in. pwr. Saw blade','11/12/96',32,15,14.99,0.05,21344);
INSERT INTO PRODUCT VALUES ('14-Q1/L3','9.00-in. pwr. Saw blade','11/12/96',18,12,17.49,0.00,21344);
INSERT INTO PRODUCT VALUES ('156-QQ2','Hrd. Cloth, 1/4-in., 2x50','8/14/96',15,8,39.95,0.00,23119);
INSERT INTO PRODUCT VALUES ('1558-QW1','Hrd. Cloth, 1/2-in., 3x50','8/14/96',23,5,43.99,0.00,23119);
INSERT INTO PRODUCT VALUES ('2232/QTY','B&D jigsaw, 12-in, blade','10/29/96',8,5,109.92,0.05,24288);
INSERT INTO PRODUCT VALUES ('2232/QWE','B&D jigsaw, 8-in, blade','9/23/96',6,5,99.87,0.05,24288);
INSERT INTO PRODUCT VALUES ('2238/QPD','B&D cordless drill, 1/2-in.','10/19/96',12,5,38.95,0.05,25595);
INSERT INTO PRODUCT VALUES ('23109-HB','Claw hammer','11/19/96',23,10,9.95,0.10,21225);
INSERT INTO PRODUCT VALUES ('23114-AA','Sledge hammer, 12 lb.','12/1/96',8,5,14.40,0.05,null);
INSERT INTO PRODUCT VALUES ('54778-2T','Rat-tail file, 1/8-in. fine','6/14/96',43,20,4.99,0.00,'21344');
INSERT INTO PRODUCT VALUES ('89-WRE-Q','Hicut chain saw, 16 in.','7/6/96',11,5,256.99,0.05,'24288');
INSERT INTO PRODUCT VALUES ('PVC23DAT','PVC pipe, 3.5-in., 8-ft','12/19/96',188,75,5.87,0.00,null);
INSERT INTO PRODUCT VALUES ('SM-18277','1.25-in. metal screw, 25','11/28/96',172,75,6.99,0.00,'21225');
INSERT INTO PRODUCT VALUES ('SW-23116','2.5-in. wd. screw, 50','9/23/96',237,100,8.45,0.00,'21231');
INSERT INTO PRODUCT VALUES ('WR3/TT3','Steel matting, 4''x8''x1/6", .5" mesh','11/16/96',18,5,119.95,0.10,'25595');
now when I do the following:
SELECT * FROM PRODUCT;
only the first 4 columns is returned!
I tried setting the following:
SET WRAP ON
SET TERMOUT OFF
SET VERIFY OFF
SET TRIMSPOOL OFF
SET LINESIZE 2000
SET LONG 200000
SET PAGES 0
And now only two columns appear.
Please help.

If the column should be CHAR(200), then you should leave it alone - don't change it to CHAR(50) only because you can't display it properly.
Instead, you are probably OK by showing only the first 50 characters when you query the table. You could do that in the query itself, like this:
select p_code, substr(p_descript, 1, 50) as p_descript, p_indate, ...
Alternatively, you can tell SQL Plus to display the column in 50-character width, with a SQL Plus command - you were trying to do that, you just didn't find the right command. It is the column command; specifically in this case:
column p_descript format a50
(note this is NOT followed by semicolon ; since it is not a SQL command) This will wrap the values that are actually longer than 50 characters. If instead you want them to be truncated, issue an additional SQL Plus command:
set wrap off

Related

SQL Query to Map Debit Transaction to Deposited Transaction in FIFO manner

I am seeking help here to Map outgoing debit Transaction to deposit Transaction. Attached is the screen shot on the type of dataset I receive.
explanation of the data -
A customer can buy a Point Pack (Think of this as a Deposit of dollar amount to their account). Customer can use that Deposited dollar amount to active\Renew certain services\products(a debit Charge to their account).What I am looking for here is to Map all the debit Transaction to its deposited transaction on the basis of First In First Out (Fifo). customer can stop using certain product\service and may eligible for a credit(as a refund to their account and the point goes back to pool)
Original Data Set
Desire Output
Thank you for reply. Here is DDL and sample data.
Create Table #salesTran
(customer Varchar(20),
TransactionID varchar(20),
TransactionDate Datetime,
TransactionType Varchar(20),
TransactionSubType Varchar(20),
Points Float,
SerialNumber Varchar(50),
ServiceType Varchar(20)
)
INSERT INTO #salesTran VALUES ('Cust001','ABC001','1/1/2021 21:20:27', 'Credit','In',100,'ABCD-EFGH-IJKL-123','PointPack');
INSERT INTO #salesTran VALUES ('Cust001','ABC002','1/2/2021 18:22:36', 'Debit','Out',50,'ABCD-0001','Service A');
INSERT INTO #salesTran VALUES ('Cust001','ABC003','1/2/2021 13:56:55', 'Debit','Out',30,'ABCD-0002','Service B');
INSERT INTO #salesTran VALUES ('Cust001','ABC004','1/31/2021 20:16:31', 'Credit','In',100,'ABCD-EFGH-IJKL-456','PointPack');
INSERT INTO #salesTran VALUES ('Cust001','ABC005','2/1/2021 16:21:00', 'Debit','Out',20,'ABCD-0003','Service B');
INSERT INTO #salesTran VALUES ('Cust001','ABC006','2/1/2021 16:49:15', 'Credit','Refund',20,'ABCD-0003','Service B');
INSERT INTO #salesTran VALUES ('Cust001','ABC007','2/1/2021 16:49:20', 'Debit','Out',30,'ABCD-0003','Service C');
INSERT INTO #salesTran VALUES ('Cust001','ABC008','2/1/2021 20:46:42', 'Debit','Out',50,'ABCD-0001','Service A');
INSERT INTO #salesTran VALUES ('Cust001','ABC009','2/1/2021 20:21:51', 'Credit','In',50,'ABCD-EFGH-IJKL-789','PointPack');
INSERT INTO #salesTran VALUES ('Cust001','ABC010','3/2/2021 18:22:36', 'Debit','Out',50,'ABCD-0001','Service A');
INSERT INTO #salesTran VALUES ('Cust001','ABC011','3/2/2021 13:56:55', 'Debit','Out',30,'ABCD-0002','Service B');

Postgres insert into a table

I have a SQL script like this which I run from the command line using psql:
insert into "A"."B" values
(1, 'name=a', 'a#example.com', 'K')
How do I convert it into INSERT command inside a database?
INSERT INTO "A"."B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');
Also what does "A"."B" do? I read somewhere that double quotes are needed when table name has Capitals. I seem to get an error with that when I run commands inside the database.
You said that your database name was DB and your table name was B.
You can simply use the table name alone:
INSERT INTO "B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');
If you want to include the database name, then use:
INSERT INTO "DB"."B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');
The double quotes are only required when the name of any entity (e.g. table, column, etc...) is a reserved word.
You can use this query where A is schema and B is table name.
INSERT INTO "A"."B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');

SQL server--> Inserting multiple rows into a table with identity column

I wanna insert a multiple rows into a table with identity column
I have a table called 'STU' with the following columns:
SNO (Primary Key, and Identity [i.e. autoincrementing])
NAME (not null)
CLASS (not null)
SECTION (not null)
CREATE TABLE STU (SNO INT IDENTITY (1,1) CONSTRAINT PK_SNO PRIMARY KEY (SNO),
NAME VARCHAR(25), CLASS VARCHAR(20), SECTION CHAR );
The values are got inserted while executing insert query for each row individually
INSERT INTO STU VALUES('A','1','A');
INSERT INTO STU VALUES('B','2','B');
INSERT INTO STU VALUES('C','3','C');
INSERT INTO STU VALUES('D','4','D');
INSERT INTO STU VALUES('E','5','E');
but while trying to insert multiple values using single insert query in every possible shots, it took throws an error
INSERT INTO STU (SNO,NAME,CLASS,SECTION)
VALUES(NULL,NULL,NULL,NULL)
,('A','B','C','D','E','F')
,('1','2','3','4','5','6')
,('A','B','C','D','E','F');
also
INSERT INTO STU (NAME,CLASS,SECTION) VALUES
('A','B','C','D','E','F'),
('1','2','3','4','5','6'),
('A','B','C','D','E','F');
also
INSERT INTO STU (NAME,CLASS,SECTION) VALUES
('A','1','A'),
('B','2','A'),('C','3','A'),
('D','4','D'),
('E','5','E'),
('F','6','F');
also
INSERT INTO STU (SNO,NAME,CLASS,SECTION) VALUES
(NULL,'A','1','A'),
(NULL,'B','2','A'),
(NULL,'C','3','A'),
(NULL,'D','4','D'),
(NULL,'E','5','E'),
(NULL,'F','6','F');
All your Insert statements are bad:
Make sure you are supplying the same number of columns as in the INSERT statement
Make sure you are not supplying SNO (it's automatic)
Here is an example:
INSERT INTO STU (NAME,CLASS,SECTION) VALUES
('A','B','C'),
('1','2','3'),
('A','B','C');
If you are on SQL Server 2005, use UNION ALL
INSERT STU (NAME,CLASS,SECTION)
SELECT 'A' AS NAME,'1' AS CLASS, 'A' AS SECTION
UNION ALL
SELECT 'B', '2', 'B'
UNION ALL
SELECT 'C', '3', 'C'
Versions later than 2005, you could use
INSERT STU (NAME,CLASS,SECTION)
VALUES ('A','1','A'),
('B','2','B'), ...
You just need to concatenate the SQL you had in your first example.
You can't insert into the identity column (unless you turn identity insert on of course).
INSERT INTO STU (NAME,CLASS,SECTION)
VALUES
('A','1','A'),
('B','2','A'),
('C','3','A'),
('D','4','D'),
('E','5','E'),
('F','6','F');
If you do want to turn identity insert on then you'd need to do the following:
SET IDENTITY_INSERT STU ON
INSERT INTO STU (SNO, NAME,CLASS,SECTION)
VALUES
(1, 'A','1','A'),
(2, 'B','2','A'),
(3, 'C','3','A'),
(4, 'D','4','D'),
(5, 'E','5','E'),
(6, 'F','6','F');
SET IDENTITY_INSERT STU OFF
SQL Fiddle
You can write this as:
INSERT INTO STU VALUES
('A','1','A'),
('B','2','B'),
('C','3','C'),
('D','4','D'),
('E','5','E');

SSRS: How do I display a list of customers, from A - K then L to Z, without having two separate reports?

I would like one report with a drop down menu, showing:
Customers A-K,
Customers L-Z
All Customers
I have an SQL table for customers, with the standard columns (Acc No., name, address, etc).
I would like this split by name as it takes a long time to bring the result of the entire table down.
I would prefer this to be in one report. Is this possible? I am using SQL Server 2008 R2 with reporting services.
I have tried a few different methods with no luck, so I'm open to any suggestions!
Thanks for reading my question and thanks in advance if you can find the time to help!
Please feel free to ask any questions.
create table #alphab
( alphaname varchar(15));
insert into #alphab VALUES ('ANT')
insert into #alphab values ('CAT')
insert into #alphab values ('pAT')
insert into #alphab values ('mAT')
insert into #alphab values ('dAT')
insert into #alphab values ('rAT')
insert into #alphab values ('dAT')
insert into #alphab values ('lAT')
insert into #alphab values ('cAT')
insert into #alphab values ('zAT')
insert into #alphab values ('xAT')
insert into #alphab values ('wAT')
insert into #alphab values ('oAT')
insert into #alphab values ('sAT')
insert into #alphab values ('yAT')
insert into #alphab values ('uAT')
select alphaname
from #alphab
where alphaname LIKE
CASE
WHEN #alphabetorder = 1 THEN ('[A-K | a-k]%')
WHEN #alphabetorder= 2 THEN ('[L-Z | l-z]%')
END
order by alphaname

Sql Query for range

i am developing a website
there are two form searchscreen and serachresultscreen
in first form i select a range from two dropdown list (i.e From value1 to value 2)
range is for diamond clarity like in order respectively
FL,IF,VVS,VVS1,VVS2,SI,SI1,I1,I2
when i range query it on next form like
clarity>=FL and clarity<=VVS1
then it show result with all values between alphabet F to V (i.e FL,IF,VVS,VVS1,VV2,SI,I1,I2
please suggest me some answere
My required output is(when selected between from=FL to=VVS1)
then result output value FL,IF,VVS,VVS1 only
You can not use range operator BETWEEN for your String values. To address this issue create table with corresponding numeric weighting for those Diamond Clarity values.
while filtering based on Clarity fetch its order and then put all those ORDER (Numeric Number)
within Range Operator
EDIT :
CREATE TABLE DIAMOND_CLARITY
(CLARITY VARCHAR(10),
CLARITY_ORDER int
)
INSERT INTO DIAMOND_CLARITY values ('FL',1)
INSERT INTO DIAMOND_CLARITY values ('IF',2)
INSERT INTO DIAMOND_CLARITY values ('VVS',3)
INSERT INTO DIAMOND_CLARITY values ('VVS1',4)
INSERT INTO DIAMOND_CLARITY values ('VVS2',5)
INSERT INTO DIAMOND_CLARITY values ('SI',6)
INSERT INTO DIAMOND_CLARITY values ('SI1',7)
INSERT INTO DIAMOND_CLARITY values ('I1',8)
INSERT INTO DIAMOND_CLARITY values ('I2',9)
Query to fetch records between ranges
SELECT CLARITY from DIAMOND_CLARITY where CLARITY_ORDER
BETWEEN
(SELECT CLARITY_ORDER FROM DIAMOND_CLARITY where CLARITY='FL')
AND
(SELECT CLARITY_ORDER FROM DIAMOND_CLARITY where CLARITY='VVS')