I have a single query in teradata sql assistant:
select ID from RetailSales;
I want to execute this query multiple times with different columns in select statement
Ex: select Name from RetailSales, select DOB from RetailSales,.. so on for 10 columns.
Is there any way to do it (without creating macros or procedures)?
Related
I have a history table that I am trying to insert data into. The data in the source table is horizontal i need the data vertical. In order to do this, I run 36 queries. I would like to run 1 query that has 36 select statements in it. I wrote a select query that has a union it it. it runs fine and i get the data. when i take that query and convert it to an insert into query, i get an error at the UNION clause
Anyone run into this?
Save your working union select query as a query.
Then use this query as source in a new append query which will append records to your table.
I'm wondering if it's possible to store a result-set of a select query into a mysql variable, while using a stored procedure?
Example of a select query:
SELECT * FROM registrations WHERE user_id = <input_stored_proc>
I have multiple select queries that I'd like to run in that stored procedure and would like to store each result-set into a different variable.
What I'd like to do is, call that stored procedure from any application and be able to do something like this: (all SELECT queries require the user_id input)
CALL <stored_proc_name>(<user_id>)
And then use the variables, so I can e.g. loop through the rows of any executed select query.
Thanks.
I'm new to SQL, I have a table, in that table column have following data
/message/charge/392bd2c574-90e7-da9f70ed01b2/text
I executed my query
select message from emp_data;
output:
/message/charge/392bd2c574-90e7-da9f70ed01b2/text
but I want only
392bd2c574-90e7-da9f70ed01b2
value in output so how to split it through SQL query
try substring_index function-
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('/message/charge/392bd2c574-90e7-da9f70ed01b2/text','/',-2),'/',1);
You can use below query including your field and table-
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(`message`,'/',-2),'/',1) FROM emp_data;
Note: Further you can add other fields and where condition as per your requirement.
I am using stored procedure. I am passing some input parameter to stored procedure like p_type. Based on this condition i need to get either 1 column or 3 column as output
like
select
a_orderid AS OrderId,
t_logisticpartner.a_name AS Logistics,
t_shipment.a_shipmentid AS ShipmentId
from order some join comitions;
If p_type is 1 then i need all 3 columns or else just orderid column. I need to have aliases also.
Two MySQL solutions:
Write big switch with all possible SELECT queries using CASE or IF statements.
Construct result SELECT statement, and then execute it using MySQL prepared statements.
I am having a sql query
select devices.id, devices.type_designator_id, devices.color, devices.status,
devices.device_build, users.username
from devices,users
where
devices.user_id=users.id and devices.user_id=1608
ORDER BY devices.id;
Now it will give me 6 output from two tables devices and users.
Now I want to extract only one output from above query (without changing the anything) type_designator_id, to put it as a parameter for next sql query with different table.
Say new table is Type_designators with a parameter name id, which is same as the type_designator_id from the previous query.
You could consider creating a view defined by the query you've shown above, and using that view in your new query.