snowflake output in table format - snowflake-cloud-data-platform

When I queried a external table(pointed to CSV file) in snowflake , The results are displayed in JSON format.
How can I retrieve my results in tabular format without use any such below sql . I wanted to do select * from table and I expect it to display in display format.
select
value:c1::int as month_num
,value:c2::string as month_name
from mytable
;
any thoughts? Thanks.

Create a view on your table and use select * on the view
create or replace view my_view as
select value:c1::int as month_num ,value:c2::string as month_name from mytable;
select * from my_view;

Related

SSRS report not showing image from DB

I have a table with varbinary(MAX) field to store images.
I have updated this table with the following SQL:
insert into table1
select * FROM OPENROWSET(BULK N'C:\capture.png', SINGLE_BLOB) AS img
Select from this table looks like this:
I have created a dataset that pulls this image from the table:
select * from table1
Then for the image I use from database and this is its source in the expression:
=First(Fields!Image.Value, "DataSet1")
MIME is image/png
The image is not showing in the report. All I get is the red X.
Any idea what might be wrong?
Thanks

How to get Distinct records from SQLITE table in flutter?

I am having a table like this.
I want to write a query in sqlite in flutter to get all the records where id are different. For above table output should be:-
How should I work this out?
Try this query
SELECT * FROM table_name GROUP BY id
Just use the word "distinct on columnName" after the select statement like this:
select distinct on id *
from table
For reference and more clarity check this out.

How to store complete Stored_Procedure content in a table as a record in sql server?

I am working on SSIS, through which I have to copy the complete Stored procedure from one SQL server instance to another instance in a table as a record. How can I achieve that? For eg:
-----sp------
Create PROCEDURE simplesp
AS
SELECT * FROM sample
GO;
-------table----------
select ID,SP_info from SP_Content;
the above table query should return a value like,
ID SP_info
---- ------------------------------------------------------
1 Create PROCEDURE simplesp AS SELECT * FROM sample GO;
You might be looking for something like this.
SELECT row_number() OVER (ORDER BY OBJECT_NAME(OBJECT_ID)) ID,
OBJECT_NAME(OBJECT_ID) as Name,
definition as SP_info
FROM sys.sql_modules
WHERE
objectproperty(OBJECT_ID, 'IsProcedure') = 1

Filter xml column in T-SQL from WhoIsActive

Simple question, how do I query an XML column containing values like this:
<?query --
select statistic_name_id, convert(varchar(1024), statistic_name), datasource_id, statistic_class_id, datatype_guide, derived, using_wide_string from spotlight_stat_names
--?>
I use WhoIsActive from Adam Mechanic with a destination table. I got a lot of rows and I want to filter out some. Please help.
select * from WhoIsActivetable
where cast(sql_text as varchar(max)) like '%statistic_name_id%'
select sql_text, cast(sql_text as varchar(max)) from WhoIsActivetable

Retrive data from partition table using select

I created partitions on one table. I have created the partitions using column year.
I want to retrieve the data from partition table using clause.
How can I write my select clause?
Something like this...
-- fetch all the rows on the 2012 partition
SELECT
t.name,
t.year
FROM
mytable AS t
WHERE
$PARTITION.<partition_function_name>(t.year) = $PARTITION.<partition_function_name>(2012)
For more info look here.

Resources