How to copy to clipboard a UNIQUEIDENTIFIER value in SQL Azure Manager? - azure

I'm trying to get a value from a UNIQUEIDENTIFIER column from a table in the SQL Azure manager (silverlight).
Right click on the data only get me to the Silverlight "About" page, double click do nothing.
It works on a varchar column (the manager allow to select text from the value, and the COPY), but not on a UNIQUEIDENTIFIER column.
I tried to use the following query :
select convert(nvarchar(50), guidColumn) from table
But, it doesn't allow to select the data either.
Thanks

Related

Reference an excel cell in a Where statement to change the Query

I would like to use an Excel cell to change the reference data in a Where statement so that I don't have to keep going into power query to change the statement.
Instead of the 31690 in the below code I would like to reference cell B7 in sheet1 of the same Workbook instead.
Is this possible? and if so how?
Thanks in advance.
WHERE ORDERDATE >= #Month13#(lf)#(tab)and STOCKCODE is not null#(lf)#(tab)AND SALESORD_HDR.ACCNO = '31690'
Maybe something like this?
For this approach to work, you need to make sure your spreadsheet has a table and the table's range starts with A1 and spans beyond the cell with the value in it--in this case, B7. Here's an example:
I started by creating this spreadsheet with a table named Table1:
Then, I used Table1 as the source in Power Query.
Notice that with the table above, what was row 7 is row 6. This is because the column headers don't have row numbers in Power Query. This change in row numbering matters for finding your targeted cell.
Then I added some custom M code. This code first extracts the second column's name from the list of column names. (Because the second column would be column B of the spreadsheet.) Then it uses that second column's name to create a table of that column's values, from which it then extracts the sixth row entry. (Because that sixth row entry would be the seventh row entry in the spreadsheet.) Note that the {1} points to the second column and the {5} points to the sixth row. That's because Power Query indexing starts at 0.
I went into Advanced Editor and renamed the step from Custom to DateVariable:
DateVariable = Table.Column(Table1_Table, Table.ColumnNames(Table1_Table){1}){5},
Then I added some more custom M code to concatenate the DateVarable with the rest of your SQL statement as an example:
Here's my M code:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
DateVariable = Table.Column(Source, Table.ColumnNames(Source){1}){5},
SQL_Statement = "WHERE ORDERDATE >= #Month13#(lf)#(tab)and STOCKCODE is not null#(lf)#(tab)AND SALESORD_HDR.ACCNO = '" & Text.From(DateVariable) &"'"
in
SQL_Statement
Simple solution using a named range
First, select cell B7 and enter a name in the Name Box (e.g. CellReference). Then right-click on the cell and click on Get Data from Table/Range.
This opens the Power Query Editor with a query that returns a table containing the cell from the named range. Open the advanced editor, delete the entire content of the query and type Text.From(Excel.CurrentWorkbook(){[Name="CellReference"]}[Content][Column1]{0}) and click on Done, this is what it should look like:
Note: Text.From() is used so that value returned by CellReference can be concatenated with the SQL query using &. Also, this function is preferable to Number.ToText() which does not work with text values.
Finally, insert the query name in your SQL query: WHERE ORDERDATE >= #Month13#(lf)#(tab)and STOCKCODE is not null#(lf)#(tab)AND SALESORD_HDR.ACCNO = "&CellReference
Note that if the cell contained a text value instead, then you would need to adjust the syntax like this: ... SALESORD_HDR.ACCNO = '"&CellReference_Text&"'"
How to deal with warnings: new query permission and Formula.Firewall
How to give permission to run all new native database queries
Depending on your Query Options settings, you may get this warning message regarding the permission to run the modified SQL query each time CellReference contains a new value:
If you are certain that the cell will never contain a string of characters that could modify the database, you can disable this warning message by going to File -> Options and settings -> Query Options. Under GLOBAL, go to Security and uncheck Require user approval for new native database queries.
Note that this is a global setting that is immediately applied to all your Excel files, including those that are currently open.
How to disable the Formula.Firewall warning message
Depending on your Privacy Levels settings, you may get a Formula.Firewall warning message preventing the query from being executed:
If you are in a situation where you can disregard privacy levels, you can disable this message by going to File -> Options and settings -> Query Options. Under CURRENT WORKBOOK, go to Privacy and select Ignore the Privacy Levels and potentially improve performance.
Click on OK and refresh the query.
If, on the other hand, your workbook needs to preserve a privacy level of Private or Organizational, to my knowledge there is currently no way of integrating CellReference to a SQL query (even using a SQL parameter set with the Value.NativeQuery function or a Power Query Parameter ) without raising this warning message. The only solution would be to include CellReference in another step in the query, but then the filtering will occur in Power Query and not at the server level: query folding is interrupted when a step includes a query/function/parameter that is linked to an external data source including a named range in the workbook itself.
If your workbook privacy level is set to Public, you should be able to avoid this warning message by using the Value.NativeQuery function (you can even enable query folding for further query steps if you are using a SQL Server or PostgreSQL database). If you still get the warning message, you can try combining the two queries accessing each data source (the database and the worksheet) into a single query.
Note: these steps were tested with Excel Microsoft 365 (Version 2107) on Windows 10 64-bit connected to a local SQL Server 2019 (15.x) database.
This answer was prepared by referring to many blog posts by Chris Webb (linked above) and by Ken Puls (like this one).

PowerBI-DirectQuery - Separate Time From DateTime

i currently have a DirectQuery set up on a SQL Server. There you will find field in the format "dd.mm.yy H:i:s".
Is it possible to separate the time from the date? So that I can set a filter?
If your column name is DateTime, you can separate Time from them in Power Query Editor. Just add a custom column with this below code shown-
= Time.From([DateTime])
OPTION 2
You can also split the value using Space (" ") which will separate Date and Time in 2 column in power query-
Output will be as below-
Unfortunately, what mkRabbani suggest does not work with DirectQuery connection - you cannot split column nor use "Time.From()" and preserve DirectQuery - Power BI will immediatelly suggest turnig into Import mode to apply the changes...
If you don't need it at the Power Query level but at the model level, you can create calculated column which will equal to your original Date-Time column. This calculated column then could be set to Date or Time data type.
Miro.
If we want to separate date and time from the DateTime columns in the DirectQuery, you can do it by changing the SQL query while importing the data.
Go to Power Query Editor and click on the settings icon in Applied Steps.
Data source setting
Then, click on advance options in the SQL server database setting and add the below SQL statement for your table. Change the column name based on your table column name
SELECT *,
[CreateDate_Date] = CONVERT(date, [CreateDate]),
[CreateDate_Time] = CONVERT(time, [CreateDate])
FROM [dbo].[Table]
SQL Query
Choose the Server and Database name and click Ok

How to create a new table from Query data and change rows to column in Power BI

I am new to Power BI. I have searched a solution, but I can't find the one match my issue.
I use direct query to SQL Server to generate data table in Power BI. My query result as below:
And I want to create a new table and transform the data to be as below:
Really appreciate any help or idea.
Thanks
You need to pivot the Factory column to get the desired result.
In Power BI Desktop designer, click Transform data button from the Home ribbon tab to open Power Query Editor. First, delete the Comment column (or don't select it at first place) by right clicking on it's title and select Remove. You don't need it. Then select Factory column and click Pivot Column button from Transform tab:
and select Volume for values column:
This will pivot the column, i.e. make a separate column for each of the values in it, and give you the desired result:
In addition (you said you are using a DQ to get the data), you can also do the same transformation in the database query too.

How do I copy and paste results from ORACLE SQL Developer to Excel while taking Null values into account?

I have Googled this issue and have looked at previous Stackoverflow questions. I am trying to figure out how to copy and paste from Oracle SQL Developer into Ms Excel. I have tried right clicking my results and clicking Export and following the steps to Export to clipboard and I have also tried highlighting all rows and pressing Ctrl + Shift + C and pasting into Excel. In both cases, when a field has a Null value in SQL Developer, it will just skip the cell in Excel. For example if Field1 has a value of 'Oracle', Field2 has a value of Null, and Field3 has a value of 200, when I paste into Excel cell A2 (first row is headers) will have a value of 'Oracle', then B2 instead of being blank will have a value of 200. How do I account for Null values when pasting? The other issue is that I am working through Citrix so I am not able to easily save work from SQL Developer to my desktop (in fact it is damn near impossible).
This is a known issue in the newest SQL developer version 19.2:
A BUG with Excel exports containing NULL DATE values causes the Excel
file to be truncated, use CSV as a workaround or fall back to version
19.1
I'm not sure why you're having trouble because I am not. True, I am not using the Export feature but you haven't said that you must use that feature. To continue the conversation in comments will be a bad idea.
First, I am using SQL Developer 19.2.1.247 and Excel 16.24 on macOS (but the OS should not matter).
Here is the query that I am using to test the copy & paste capability:
select 1, null, 2 from dual
union all
select null, 3, 4 from dual
union all
select 5, 6, null from dual
union all
select null, null, null from dual
If you reproduce good results with this query but bad results with your query, then I suggest you edit your post and include an MCV example query that produces bad results.
I select the query and press [Run Statement]. This creates a Query Result window that looks like this:
Then I put my cursor in the Query Result window and select all rows displayed by pressing Meta-A (⌘A or ^A) and then copy the selection by pressing Meta-C (⌘C or ^C). Then I see this:
Then I place my cursor in cell A1 in an Excel sheet and paste the clipboard by pressing Meta-V (⌘V or ^V). Then I see this:
Notice all four row's cells in the Excel sheet are correct w.r.t. the query. I did nothing special, not even invoking Menu->Data->Text to Columns. It was all done "automatically".

Change data source of a list table in Excel 2010

Is there a way to change the data source of a list table in Excel? It's easy to change the data source of a pivot table but the only way I have found to change the data source of a list table is to delete the table and start again.
Just to be clear, what I mean by a list table is what you get when you set up a connection to a table or query in Access (for example) and then click on "Existing Connections" under the Data tab.
I would prefer a method using the usual user interface but if there is a method that works only in VBA, that would be fine.
You can do it from the Excel interface without VBA.
Under the Data tab, click on Connections.
From the Workbook Connections dialog, click Properties.
From the Connection Properties dialog, click Definition.
Browse for a connection file and then select a table.
That's it.
If your data source is inside Excel on another sheet and you're using OLE DB Query, you might find changing the data source impossible (which was the case with me).
To change the data source in this instance, you need to click on Resize Table under the Table Design tab in Excel, as can be seen below:
When you click on this, you are able to change the range of your query, as can be seen below:

Resources