How can I query the results of a query in Server Explorer in Visual Studio? - tsql

I can get the results of a Stored Proc from Visual Studio by following these steps:
0) Select View > Server Explorer
1) Locate the Data Connection that contains the SP of interest.
2) Right-click the SP and select Execute; if any args are required, it will allow you to populate those in a dialog and then proceed with the execution
Provided that you have provided valid args (and the SP returns data), the results will display in a grid in a T-SQL Results tab.
Now, though, what if you want to query that "dataset" that has been returned, such as to sum the values of a particular column - can that be done right there from within Visual Studio.Server Explorer.T-SQL? If so, how?
UPDATE
I believe Khazratbek, but I can only get this far in a New Query instantiated by right-clicking the Tables folder beneath the Data Connection:
SELECT SUM(QtyShipped), SUM(QtyOrdered) FROM CPSData.
...the options available as a drop down following that final "." do not contain the results of the Stored Proc (SQLQuery1.sql).
Is it really possible?

Server Explorer -. Right click on Tables -> New query. Write your query (you may select from your SP execution results) and just click on triangle sign. Sorry, if I misunderstand your exact question.

Let's think that your stored procedures gives you logins and passwords of users:
select login, password from users;
You are taking one million result, for example. And you don't need to change your stored procedure, but you want to make some job with your results (selecting in some order, changing the order, select by some condition, so on).
Let's continue. Your stored procedure gives you a two column: it is column login and password. So we may consider the results of your SP execution as some table. To work with your result do next steps:
Server Explorer -> Your_database_connection -> Right click on Tables -> New query
Then write the following code there:
Declare #temporary_table_variable table(login varchar, password varchar); --or without datatypes
insert into #temporary_table_variable(login, password) exec MyStoredProc;
SELECT * from #temporary_table_variable where id > 1000; --it is just a simple example
Hope it helps

Related

How do I format the script stored in information_schema.routines

We have an internal resource used by our developers and support to help identify data issues when we are diagnosing problems in our system. It's used to support a collection of data feeds and they are very customized. What we would like to do is allow one of our users to click the name of a stored procedure and then view the CREATE script of that stored procedure. This is done on an ASP.NET form.
I can get this information by using this statement:
select object_definition(object_id(routine_name))
from information_schema.routines
where routine_name like '%sprocname%'
However, the returned script is unformatted and in a single cell, on a single line. Is there a way for me to format this as if I had right-clicked on the stored procedure in SSMS and select "Script stored procedure as CREATE to"? Because it is all on a single line, if I have commented any portion of the procedure out using two dashes it comments the entire rest of the procedure that follows it.

Delete data based on date from DOMO

I need to delete data from a dataset. I read this post that I think would help (https://dojo.domo.com/discussion/comment/46624#Comment_46624) but Im not sure where to run this query to delete from the table.
Please let me know if these are the correct steps:
click SQL in DOMO url -> MySQL -> input datasets (add the table I want to delete rows from) -> transform (
add my delete from statement:
DELETE FROM
my_table
where `loaded_date` >= '2019-10-01' and `loaded_date`<= '2019-11-01';)
-> output datasets (just do select * from table? does it matter what I enter here?, can I just limit to 10?)
thanks!
Ok so I found a way two ways to do this. Within my question I mentioned where to go to run a DataFlow, that would be one way to do this. But it matters what you write for the output dataset as that would be the new dataset you use.
So I did SELECT * FROM my_table;
The second way to do this is to delete the version history, so lets say I get my data daily to DOMO, I would go to the dataset url, and add this to the end: ?_f=dataRepair . This just refreshed the page, but at the top there is a new button to click on called "data repair" select that and it will take you to all your versions. You can filter it by date as well and just delete.

Can't remap fields - map fields window is missing new table

I have a Crystal Report with a database command:
The command has a join clause that can be removed and read from a table in the database, because it represents static data. I add this table (called _System) to the database expert:
Now I edit the command to remove the join and columns that reference this table. Since the report fields that depended on these columns are no longer mapped, this causes the Map Fields window to appear:
...which does not have the new table in it. If I cancel out of this I am back to where I originally was. If I hit OK without mapping, all of the unmapped fields on the report are deleted (suffice it to say... I was not expecting this >:( )
I have tried adding links between the command and the new table, and refreshing report parameters, but these have had no effect.
One workaround is to manually replace every field in the report, but this is very labour intensive.
Here is the outline of the command before:
SELECT ACT.Account_Code, ACT.Company, ACT.FName, --etc
STM.CompanyName AS 'DLRName', STM.Address_1 AS 'DLRAddress', STM.City AS 'DlrCity' --etc
FROM Accounts AS ACT
JOIN _System AS STM ON 1 = 1
GROUP BY ACT.Account_Code, ACT.Company, ACT.FName, --etc
STM.CompanyName, STM.Address_1, STM.City --etc
And after:
SELECT ACT.Account_Code, ACT.Company, ACT.FName, --etc
FROM Accounts AS ACT
GROUP BY ACT.Account_Code, ACT.Company, ACT.FName --etc
I have removed the JOIN on the _System table, and all referenced columns.
It appears to not be recognizing your _system table as a new source.
I would :
1) leave your command object SQL unchanged & get the issue worked out with the _System table, then
2) ensure that you are able to establish a join between the command object fields and the _System table fields, and lastly
3) then remap the fields.
Step two I suspect is the source of the problem, as your join condition is "ON 1 = 1" which I assume to mean that you may not have a common key field in both tables.
Note that your original command SQL selects STM.Companyname AS 'DLRName'.
Hence, crystal now know of a field called DLRName, but does not know of a field called CompanyName, hence it cannot make the association between DLRName in the old source, and CompanyName in the new source...
Likewise with the rest of the fields that are being moved from the command object to an attached table. if no name match exists...Crystal cant make the connection. However...it would list all unmatched fields that are on the report, and all unused fields in the recognized data sources, and allow you to specify the matches yourself.
But it does not...which tells me that something has gone wrong with the attempt to attach/open the _System table. Hence..you need to get that worked out first, then make the field adjustments.
If this doesnt get you thru...then show some sample data so I can see how the two tables are relating ( ensure some examples exists where there is a row match from both tables ).
I had the same problem a while ago.
Unfortunately I can't find anything online that helps, or maybe wasn't looking hard enough. I just noticed that in my case, that particular field that isn't showing in the map field dialogue box has nvarchar(max) as its datatype (in view).
I tried to force the datatype with CAST(missingfieldname as nvarchar(20)) as missingfieldname (I did this in the view), and voila, it magically appears in the map field dialogue box.
It seems that field mapping dialogue box aren't showing fields with blob texts.
I know this question was asked 4 years ago. But hopefully, this comment could help future solution seekers regarding this absurd and weird problem. I just got lucky seeing what's unique about that particular missing field.

TSQL sysdatabases query returns 'Server Name'

I use the following query:
select name from sys.sysdatabases
and get an additional column returned called Server Name
Where does this column come from, as it is a handy column to have in ssrs but will not replicate, it only works in Management Studio
What Probably Happened
My guess is that you opened your query window by right-clicking on a registered server group and choosing "New Query."
Microsoft SQL Server Management Studio (SSMS) offers a feature where it will run the same query on multiple servers and then combine the results into a single results grid. To help you sort out which server returned which data rows, by default SSMS adds a Server Name column to this grid. This feature can be accessed by first adding the servers of interest to the registered servers list and then right-clicking on the relevant registered server group and choosing "New Query."
How to Achieve the Same Effect in SSMS
Depending on the exact data you want, you can get the executing server's name via the T-SQL variable ##SERVERNAME or the SERVERNAME property of the SERVERPROPERTY function (see the remarks section of MSDN's documentation on SERVERPROPERTY for details on the difference between what these two approaches retrun).
For example, if you choose to use##SERVERNAME, you can fetch that name via a stand-alone query (SELECT ##SERVERNAME). You can also achieve functionality similar to SSMS's Server Name column by adding , 'Server Name' = ##SERVERNAME to the end of your SSRS report's SELECT column list (e.g. SELECT FirstName, LastName, 'Server Name' = ##SERVERNAME FROM ....).

Entity Framework - stored procedure

My stored procedure looks like this:
create Procedure procLoc
AS
BEGIN
select
pr.name, loc.address
from
Profile pr
join
Location loc on pr.id = loc.id
END
For the add function Import dialog box that comes up, there are the following options
None
Scalars
Complex
Entities
Which option would I select in this scenario?
Since your stored procedure is returning multiple values: pr.name,loc.address, you'll only have 2 choices- Complex or Entities. If you already have an entity mapped with Name/Address properties you can choose it, otherwise choose complex. I usually click the Get Column Information button and then Create New Complex type and let it generate one for me.