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
Related
I have a XML column in a SQL Server database that I need to be able to extract the data from, and spread into multiple columns in a SQL query. The table itself runs to multiple millions of rows of data.
The XML data is stored as:
<dreg>
<dtype>Test</dtype>
<dOS>Test</dOS>
<dmake>Test</dmake>
</dreg>
When I try to run the SQL query below, the XML data is returned in the view as one column:
select
Id,
dID,
Meta /*<- XML data*/
from
data_table
However, if I run the following SQL query:
select
ID,
dID,
cast(Meta as XML).value('(/dreg)[1]', 'nvarchar(100)') as data
from
data_table
The resulting column 'data' in the viewer for the XML is:
TestTestTest
How do I parse the XML correctly, so that the 3 values in the XML are in separate columns in the SQL viewer?
Try something like this to extract the separate XML elements under <dreg> as separate values:
select
ID,
dID,
DType = Meta.value('(/dreg/dtype)[1]', 'nvarchar(100)'),
DOS = Meta.value('(/dreg/dOS)[1]', 'nvarchar(100)'),
DMake = Meta.value('(/dreg/dmake)[1]', 'nvarchar(100)')
from
data_table
If Meta really is a column of type XML, there's absolutely no need for a CAST(Meta AS XML) ....
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;
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
I know this thread: Comparing Image Data Types In SQL but it isn't helpful
I'm trying to write a trigger in T-SQL (SQL Server 2008) which would check if an image of an article was changed and report it in some special table. The database uses Image datatype and I'm not in power to change it.
I tried:
ALTER TRIGGER PhotoUPDATE
ON ARTICLE
FOR UPDATE
AS
DECLARE #ID numeric (18,0),#PHOTO_NEW image,#PHOTO_OLD image
SET #ID = (SELECT ID FROM inserted)
SET #PHOTO_NEW = (SELECT PHOTO FROM inserted)
SET #PHOTO_OLD = (SELECT PHOTO FROM deleted)
IF (#PHOTO_NEW<>#PHOTO_OLD)
BEGIN
INSERT PhotoCHANGED (ID,DATE)
VALUES(#ID,GETDATE())
END
GO
I get error:
The text, ntext, and image data types are invalid for local variables.
When I tried without variables:
IF ((SELECT PHOTO FROM inserted)<>(SELECT PHOTO FROM deleted))
I got:
Cannot use text, ntext, or image columns in the 'inserted' and 'deleted' tables.
What else could I try?
You say
The database uses Image datatype and I'm not in power to change it.
Well in that case you can't do this then. image is deprecated. It is not permitted to access image columns in the inserted/deleted tables. Attempting to do this will cause the error
Cannot use text, ntext, or image columns in the 'inserted' and
'deleted' tables.
It is possible to get the post update column value by querying the base table but there is no way to get the DELETED.PHOTO value to compare it with.
You will need to get the person responsible to change the column datatype to varbinary(max).
ALTER TABLE ARTICLE ALTER COLUMN PHOTO VARBINARY(MAX) NOT NULL
Then you can access it inside the trigger and compare for equality.
Your trigger is broken as well. Updates can affect multiple (or zero) rows. Not always exactly one.
Also you should check IF UPDATE(PHOTO) to skip doing it if the column wasn't touched.
ALTER TRIGGER PhotoUPDATE
ON ARTICLE
FOR UPDATE
AS
SET NOCOUNT ON;
IF UPDATE(PHOTO)
BEGIN
INSERT PhotoCHANGED
(ID,
DATE)
SELECT I.ID,
GETDATE()
FROM inserted I
JOIN DELETED D
ON I.ID = D.ID
AND EXISTS (SELECT I.PHOTO
EXCEPT
SELECT D.PHOTO)
END
I am having trouble trying to render images from an Image column in SQL Server. I got the image data from a client db using straight copy and paste from the grid results, as we had trouble with the export process.
I am aware that there is truncation happening after 65k, but is there any other reason why you can't copy from one Image column grid data result and paste into another? And if so, is there another way to copy the data apart from Tasks > Export?
Note, when I extract the mime-type from the byte[] array, it comes back as text/plain, so I'm also hoping that there isn't some special behaviour required by the original coders to treat the data.
Try using a SQL statement to do the update instead:
UPDATE table1
SET table1.Col_Image = (SELECT table2.Col_Image FROM table2 WHERE table2.ID = 2)
FROM table1
WHERE table1.ID = 1
Have you tried INSERT...SELECT, to select the image for the table #1 and insert them into table #2?
insert into Table2 (Id2, NewImageField)
select Id1, OriginalImage
from table1
where Id1 = 1