I have created sql to retrieve information from our table and create the url for a Bing map. If I take the url from the query and paste it into a browser the map image appears.
Example: https://dev.virtualearth.net/REST/V1/Imagery/Map/Road?mapSize=600,600&mapLayer=TrafficFlow&format=png&pushpin=35.96981750,-85.03747790;64;1&key=xxx
But in SSRS if I use the url as an external image I get the red-X-in-box. No error message but no image either.
I read there should be a way to "enable external images". I've checked the box for the image. Is there another place to change the setting?
I can produce your map without any issues. Follow these instructions and make sure you can reproduce the same results, , then compare to your own report. Hopefully the issue will become apparent.
Create a new Report.
Create a new Dataset called BingMapSample and use the following dataset query, swapping the key for your Bing maps key
-- set up some static values
DECLARE #BingmapKey varchar(256) = 'XxXX-99x-
9XXXXX9XXxxxXXXxXxXxxxxXxXxx9X9XxxX9xxXxXX9xXXx99x9XXxx'
DECLARE #MapSize varchar(10) = '600'
DECLARE #Layer varchar(256) = 'TrafficFlow'
-- stick a few locations in a table, the first one is from your exmaple
DECLARE #mapLocations TABLE (coords varchar(256))
INSERT INTO #mapLocations VALUES
('35.96981750,-85.03747790'),
('50.998647,-0.105406')
-- now build up some urls to use in the report
SELECT
'https://dev.virtualearth.net/REST/V1/Imagery/Map/Road?mapSize=' + #MapSize + ',' + #MapSize
+ '&mapLayer=' + #Layer
+ '&format=png&pushpin=' + ml.coords
+ ';64;1&key=' + #BingmapKey
AS BingMapSampleURL
FROM #mapLocations ml
Now add an image to your report (use a sensible size) and set the following
Source = External
Value = =First(Fields!BingMapSampleURL.Value, "BingMapSample")
If you run the report you should see your map displayed.
To show both maps in a list, do the following
Add a 'List' to your report and set
DataSetName = BingMapSample
Resize the list's only cell to something sensible then inside the list 'cell' insert an image. Set the image properties as follows
Source = External
Value = =Fields!BingMapSampleURL.Value
The final design looked like this... (I shaded the list background just for clarity).
If you run the report you should now also see two more maps, three maps in total.
When I run the report I get this
Hope that helps...
Related
I am using SQL Server and I created a table:
create table data
(
description nvarchar(100),
url varchar(500)
)
Then I insert data:
INSERT INTO data (description, url)
VALUES ('google', 'https://www.google.com'),
('yahoo', 'https://www.yahoo.com'),
('baidu', 'https://www.baidu.com')
I want to get a clickable url when executing:
select url
from data
where description = 'google'
In other words, when I click the url returned, a chrome will be opened and go to google site.
I found that there is a method but it requires user to click twice.
What should I do?
The one that succeed to me is setting the data type of the url as xml so that it is clickable then you will get a new query window and there if you click the url with CTRL+K then the url will pop in the sql server window. For url the most appropriate data type would Varchar with preferred length but unfortunately that is not clickable within SSMS.
You can check the following URL,
basically you can click in query editor or you can set and there are few more alternatives here,
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/8c78549d-0aa2-4fed-acab-51ad11cb59a4/is-url-clickable-somewhere-in-ssms?forum=transactsql
I'm stumped on something which should be very straight-forward. I have a SQL Server database, and I'm trying to update a non-nullable varchar or nvarchar field with an empty string. I know it's possible, because an empty string '' is not the same thing as NULL. However, using the TADOQuery, it is not allowing me to do this.
I'm trying to update an existing record like so:
ADOQuery1.Edit;
ADOQuery1['NonNullFieldName']:= '';
//or
ADOQuery1.FieldByName('NonNullFieldName').AsString:= '';
ADOQuery1.Post; //<-- Exception raised while posting
If there is anything in the string, even just a single space, it saves just fine, as expected. But, if it is an empty string, it fails:
Non-nullable column cannot be updated to Null.
But it's not null. It's an empty string, which should work just fine. I swear I've passed empty strings many, many times in the past.
Why am I getting this error, and what should I do to resolve it?
Additional details:
Database: Microsoft SQL Server 2014 Express
Language: Delphi 10 Seattle Update 1
Database drivers: SQLOLEDB.1
Field being updated: nvarchar(MAX) NOT NULL
I can reproduce your reported problem using the code below with SS2014, the OLEDB driver and
Seattle and the difference in behaviour when the table has been created with MAX as the column size and a specific number (4096 in my case). I thought I would post this is as an alternative
answer because it not only shows how to investigate this difference systematically
but also identifies why this difference arises (and hence how to avoid it in future).
Please refer to and execute the code below, as written, i.e. with the UseMAX define
active.
Turning on "Use Debug DCUs" in the the project options before executing the code, immediately
reveals that the described exception occurs in Data.Win.ADODB at line 4920
Recordset.Fields[TField(FModifiedFields[I]).FieldNo-1].Value := Data
of TCustomADODataSet.InternalPost and the Debug evaluation window reveals that
Data at this point is Null.
Next, notice that
update jdtest set NonNullFieldName = ''
executes in an SSMS2014 Query window without complaint (Command(s) completed successfully.), so it seems that the
fact that Data is Null at line 4920 is what is causing the problem and the next question is "Why?"
Well, the first thing to notice is that the form's caption is displaying ftMemo
Next, comment out the UseMAX define, recompile and execute. Result: No exception
snd notice that the form's caption is now displaying ftString.
And that's the reason: Using a specific number for the column size means that
the table metadata retrieved by the RTL causes the client-side Field to be created
as a TStringField, whose value you can set by a string assignment statement.
OTOH, when you specify MAX, the resulting client-side Field is of type ftMemo,
which is one of Delphi's BLOB types and when you assign
string values to an ftMemo field, you are at the mercy of code in Data.DB.Pas , which does all the reading (and writing) to the record buffer using a TBlobStream. The problem with that is that as far as I can see, after a lot of experiments and tracing through the code, the way a TMemoField uses a BlobStream fails to properly distinguish between updating the field contents to '' and setting the field's value to Null (as in System.Variants).
In short, whenever you try to set a TMemoField's value to an empty string, what actually happens is that the field's state is set to Null, and this is what causes the exception in the q. AFAICS, this is unavoidable, so no work-around is obvious, to me at any rate.
I have not investigated whether the choice between ftMemo and ftString is made by the Delphi RTL code or the MDAC(Ado) layer it sits upon: I would expect it is actually determined by the RecordSet TAdoQuery uses.
QED. Notice that this systematic approach to debugging has revealed the
problem & cause with very little effort and zero trial and error, which was
what I was trying to suggest in my comments on the q.
Another point is that this problem could be tracked down entirely without
resorting to server-side tools including the SMSS profiler. There wasn't any need to use the profiler to inspect what the client was sending to the server
because there was no reason to suppose that the error returned by the server
was incorrect. That confirms what I said about starting investigation at the client side.
Also, using a table created on the fly using IfDefed Sql enabled the problem effectively to be isolated in a single step by simple observation of two runs of the app.
Code
uses [...] TypInfo;
[...]
implementation[...]
const
// The following consts are to create the table and insert a single row
//
// The difference between them is that scSqlSetUp1 specifies
// the size of the NonNullFieldName to 'MAX' whereas scSqlSetUp2 specifies a size of 4096
scSqlSetUp1 =
'CREATE TABLE [dbo].[JDTest]('#13#10
+ ' [ID] [int] NOT NULL primary key,'#13#10
+ ' [NonNullFieldName] VarChar(MAX) NOT NULL'#13#10
+ ') ON [PRIMARY]'#13#10
+ ';'#13#10
+ 'Insert JDTest (ID, [NonNullFieldName]) values (1, ''a'')'#13#10
+ ';'#13#10
+ 'SET ANSI_PADDING OFF'#13#10
+ ';';
scSqlSetUp2 =
'CREATE TABLE [dbo].[JDTest]('#13#10
+ ' [ID] [int] NOT NULL primary key,'#13#10
+ ' [NonNullFieldName] VarChar(4096) NOT NULL'#13#10
+ ') ON [PRIMARY]'#13#10
+ ';'#13#10
+ 'Insert JDTest (ID, [NonNullFieldName]) values (1, ''a'')'#13#10
+ ';'#13#10
+ 'SET ANSI_PADDING OFF'#13#10
+ ';';
scSqlDropTable = 'drop table [dbo].[jdtest]';
procedure TForm1.Test1;
var
AField : TField;
S : String;
begin
// Following creates the table. The define determines the size of the NonNullFieldName
{$define UseMAX}
{$ifdef UseMAX}
S := scSqlSetUp1;
{$else}
S := scSqlSetUp2;
{$endif}
ADOConnection1.Execute(S);
try
ADOQuery1.Open;
try
ADOQuery1.Edit;
// Get explicit reference to the NonNullFieldName
// field to make working with it and investigating it easier
AField := ADOQuery1.FieldByName('NonNullFieldName');
// The following, which requires the `TypInfo` unit in the `USES` list is to find out which exact type
// AField is. Answer: ftMemo, or ftString, depending on UseMAX.
// Of course, we could get this info by inspection in the IDE
// by creating persistent fields
S := GetEnumName(TypeInfo(TFieldType), Ord(AField.DataType));
Caption := S; // Displays `ftMemo` or `ftString`, of course
AField.AsString:= '';
ADOQuery1.Post; //<-- Exception raised while posting
finally
ADOQuery1.Close;
end;
finally
// Tidy up
ADOConnection1.Execute(scSqlDropTable);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Test1;
end;
The problem occurs when using MAX in the data type. Both varchar(MAX) and nvarchar(MAX) exploit this behavior. When removing MAX and replacing it with a large number, such as 5000, then it allows empty strings.
i have a table on sql like this:
CD_MATERIAL | CD_IDENTIFICACAO
1 | 002323
2 | 00322234
... | ...
AND SO ON (5000+ lines)
I need to use that info to search and replace multiple external xml files on a folder (all the tags on those XML had numbers like the CD_IDENTIFICACAO from sql query, i need to replace with corresponding cd_material from sql query "ex.: 002323 becomes 1)
I used this query to extract all the cd_identificacao to use on Notepad++:
declare #result varchar(max)
select #result = COALESCE(#result + '', '') + CONCAT('(',CD_IDENTIFICACAO,')|') from TBL_MATERIAIS WHERE CD_IDENTIFICACAO <> '' ORDER BY CD_MATERIAL
select #result
That would bring me ex.:
(1TEC45D025)|(1TEC800039)|(999999999)|(542251)|(2TEC58426)|(234852)
and changed the parameters to get the replace ex.:
(? 2000)|(? 2001)|(? 2002)|(? 2003)|(? 2004)|(? 2005)
but i don't know how to add a number (increment) on front of "?" so notepad++ would understand it (search and replace would have 5000+ results, so it's not pratical to manually add the increment).
I was able to get a workaround for this. I've used this query to get all the the terms for find and replace i needed (1 per line)
select concat('<cProd>',cd_identificacao,'</cProd>'), concat('<cProd>',cd_material,'</cProd>') from tbl_materiais where cd_identificacao <> '' order by cd_material
That would result in:
<cProd>1TEC460054</cProd> <cProd>1</cProd>
<cProd>1TEC240035</cProd> <cProd>2</cProd>
(i added the tag too to make sure no other information could be replaced as there were many number combinations that could lead to incorrect replacement)
then pasted it on a txt and i used the notepad++ to replace the space between column 1 and 2 for /r/n wich would result in:
<cProd>1TEC460054</cProd>
<cProd>1</cProd>
<cProd>1TEC240035</cProd>
<cProd>2</cProd>
then i used "Ecobyte Replace Text" Tool, pasted my result file as new selection in bottom frame, loaded all my files on a new replace group on top frame (on properties of the group, u can change directory and options), then executed the replacement, it worked perfectly.
Thx.
I'm trying to form a SQL query, using SQL Server 2014 without creating a function. I do not have permissions on the database to create functions so I have to do it with a query only.
I have a column named Test with the example value of:
Accounting -> Add Missing functionality in Payable -> Saving a blank Missing row
I want my query to return the information (of varying length) between the two arrows (->). I have tried the right, left, substring, charindex and patindex functions and various combinations of each.
Basically the query needs to be SUBSTRING(Test, CHARINDEX(' -> ', TEST) +3, <some length here>)
The length is the part I'm having a hard time figuring out. I need the full length minus the first part before and including the first -> which evaluates to:
Add Missing functionality in Payable -> Saving a blank Missing row
From that result, I need to remove everything after and including the ->, which would then leave me with:
Add Missing functionality in Payable
At the end of the day, I want to split this one column up into 3 like so:
Domain | Feature | Test
------------------------------------------------------------------------------
Accounting | Add Missing functionality in Payable | Saving a blank Missing row
Can anyone show me how to do this query, without having to write a function? Any suggestions would be greatly appreciated as I have been working on this one portion of the query for the better part of 4 hours now. Thank you in advance for your help. Have a great day!!
I tried the following query and it is woking fine for me:
DECLARE #X as varchar(1000)
SET #X = 'Accounting -> Add Missing functionality in Payable -> Saving a blank Missing row'
SELECT SUBSTRING(#X,1,CHARINDEX('->',#X) - 1) AS Domain,
SUBSTRING(#X,CHARINDEX('->',#X) + 2,LEN(SUBSTRING(#X,CHARINDEX('->',#X) + 2,LEN(#X))) - LEN(SUBSTRING(#X,LEN(#X) - CHARINDEX('>-',REVERSE(#X)) ,LEN(#X)))) AS Feature,
SUBSTRING(#X,LEN(#X) - CHARINDEX('>-',REVERSE(#X)) + 2 ,LEN(#X)) AS Test
You have to use this query:
SELECT SUBSTRING([Test],1,CHARINDEX('->',[Test]) - 1) AS Domain,
SUBSTRING([Test],CHARINDEX('->',[Test]) + 2,LEN(SUBSTRING([Test],CHARINDEX('->',[Test]) + 2,LEN([Test]))) - LEN(SUBSTRING([Test],LEN([Test]) - CHARINDEX('>-',REVERSE([Test])) ,LEN([Test])))) AS Feature,
SUBSTRING([Test],LEN([Test]) - CHARINDEX('>-',REVERSE([Test])) + 2 ,LEN([Test])) AS Test
FROM MyTable --Replace MyTable with your table name
I am new to t-sql. I have a column which stores values as url's. I want to change the first part of the url's (string), and replace only this part with another url. For example, [url//lsansps01/PMO/ITG0038 iSCOMBI Data Model Project] to [url2//lwazitest.lionsure.com/PMO/ITG0038 iSCOMBI Data Model Project]
This is my update query:
UPDATE dbo.RowUpdates
SET ProjectWorkspaceInternalHRef = REPLACE ProjectWorkspaceInternalHRef, url//lsansps01/, url2//lwazitest.lionsure.com/PMO/ITG0038 iSCOMBI Data Model Project
FROM RowUpdates
WHERE ProjectWorkspaceInternalHRef LIKE url
REPLACE uses () and not comma delimited parameters,
UPDATE dbo.RowUpdates
SET ProjectWorkspaceInternalHRef = REPLACE(ProjectWorkspaceInternalHRef, 'url//lsansps01/', 'url2//lwazitest.lionsure.com/PMO/ITG0038 iSCOMBI Data Model Project')
FROM RowUpdates
WHERE ProjectWorkspaceInternalHRef LIKE url
another questionable part is LIKE url for it to work there should be '%'+url+'%' or something similar.
You want to look at MSDN: REPLACE (Transact-SQL)
from the article:
REPLACE ( string_expression , string_pattern , string_replacement )
so you'd want to change your replace statement to (remember to use a quote (') around your strings):
UPDATE dbo.RowUpdates
SET ProjectWorkspaceInternalHRef =
REPLACE(ProjectWorkspaceInternalHRef, 'url//lsansps01/', 'url2//lwazitest.lionsure.com/PMO/ITG0038 iSCOMBI Data Model Project')
FROM RowUpdates
WHERE ProjectWorkspaceInternalHRef LIKE url
It's also worth looking at the list of String Functions (Transact-SQL) you get in SQL Server.
Replace() function will not give your expected results if #OldUrl text is found in the middle of the ProjectWorkspaceInternalHRef.
If you want to replace only the front bit, use RIGHT() (or SUBSTRING()) function after filtering them out with LEFT() function.
DECLARE #OldUrl VARCHAR(500) = 'YourOdlUrl',
#NewUrl VARCHAR(500) = 'YourNewUrl'
UPDATE dbo.RowUpdates
SET ProjectWorkspaceInternalHRef = #NewUrl +
RIGHT(ProjectWorkspaceInternalHRef, LEN(ProjectWorkspaceInternalHRef) - LEN(#OldUrl ))
WHERE LEFT(ProjectWorkspaceInternalHRef, LEN(#OldUrl )) = #OldUrl