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 ....).
Related
I use SQL Server 2014, I also have a linked SQL Server configured on it, and I need to get a particular linked server property via TSQL. The property is 'remote proc transaction promotion'. I set this option through the next code
EXEC sp_serveroption 'LinkedServer', 'remote proc transaction promotion', 'FALSE'
but I do not know how I can read the value of this option via T-SQL. Any help is appreciated.
The sys.servers system catalog view has a record for each registered linked or remote (for backward compatibility) server. The is_remote_proc_transaction_promotion_enabled column corresponds to the remote proc transaction promotion option of the sp_serveroption stored procedure. This column is of the bit data type, with true represented by 1 and false by 0.
select is_remote_proc_transaction_promotion_enabled from sys.servers where name = 'LinkedServer'
For my College assignment, I have to create a database in Access, I have done 99% of my database, apart from this section which I'm stuck on.
In my DB, I have a tickets table, which contains records on order information and a field containing a date. For my assignment, I have to create a Form which reads from a Query.
For example, in my Form i have already created i have 2 Combo boxes with the dates already pulled from the Query. I need to be able to drop down one of the boxes and input 1 date, and then drop down the other box and select a different date, press a button and it generate me a Report.
The part I am asking for help on is the expression which is used to look up the data inside the Query. I tried using this expression, which Access said was too complicated.
[Forms]![frmOrdersBetweenTwoDates]![Combo33] And [Forms]![frmOrdersBetweenTwoDates]![Combo36]
My full SQL query is:
SELECT tblTickets.CustomerID, tblCustomers.FullName, tblCustomers.AddressLine1, tblTickets.OrderNumber, tblTickets.OrderDate
FROM tblCustomers INNER JOIN tblTickets ON tblCustomers.[CustomerID] = tblTickets.[CustomerID]
WHERE ((("WHERE [OrderDate]") Between [Forms]![frmOrdersBetweenTwoDates]![Combo52] And [Forms]![frmOrdersBetweenTwoDates]![Combo54]));
My expression/query now returns the report, but there is no data inside the report. How could i fix this?
Cheers.
Should post the complete query statement. Expect the filter clause should be like:
WHERE [date fieldname] BETWEEN [Forms]![frmOrdersBetweenTwoDates]![Combo33] AND [Forms]![frmOrdersBetweenTwoDates]![Combo36]
However, I don't use dynamic parameterized queries. I prefer to use the WHERE argument of OpenReport (same for OpenForm), in VBA:
DoCmd.OpenReport "report name", , , "[date fieldname] BETWEEN #" & Me.Combo33 & "# AND #" & Me.Combo36 & "#"
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
I have a table with a GUID column and a recordId (not a guid) column. I need my report to accept a GUID as a report parameter and use it as part of the Record Selection formula to make certain the report only get the record Id's it needs.
[Linking Table] -> [Detail Containing Table]
Since the report doesn't support passing a GUID parameter directly, I was able to convert the GUID to a string and pass it in without incident. When I generate the SQL query in Crystal Designer it looks good: The WHERE clause is properly formatted and if I run the query in SQL Designer it will find all the records I need to fetch. Actually attempting to display the report fail however, it states that 0 records were found despite SQL Profiler also showing that the same SQL was fired off.
Has anyone run into this issue? Is there any way to get the Record Selection formula to not drop the records when actually displaying the report?
After working with SAP Support we were able to determine that there is a defect in 14.0.11. The SQL Query was being formatted correctly, but the record linking under the hood was using a different (and incorrect) linking order. Since the database results and internal schema wound up with different starting tables, Crystal discarded the results to prevent exceptions.
Going to Database Expert -> Links -> Order Links and checking the 'Link Ordering is Enforced' box forced the engine to use the same link ordering throughout the report in the proper order. Then the SQL query and internal record schema matched and we got records.
I'm using Crystal Reports 14 with an Oracle DB. If I have related tables Authors and Books and I selects all the authors that have book with 'code' in their title Crystal will put Books.title in the SQL SELECT clause, even if I don't use any Books fields anywhere in the report (except for the record selection). The query looks like this:
SELECT "AUTHORS"."NAME", "BOOKS"."TITLE"
FROM "AUTHORS" INNER JOIN "BOOKS" ON "AUTHORS"."ID"="BOOKS"."AUTHOR"
WHERE "BOOKS"."TITLE" LIKE '%code%'
This causes a problem because, even if I use the "Distinct" option, I will get many entries for each author (if they have more then one book with 'code' in the title). But what I want is only one entry by author. "Distinct" do not work here because each entry is really distinct, their book title are different.
How can I avoid getting "BOOKS"."TITLE" in the SELECT clause like this:
SELECT DISTINCT "AUTHORS"."NAME"
FROM "AUTHORS" INNER JOIN "BOOKS" ON "AUTHORS"."ID"="BOOKS"."AUTHOR"
WHERE "BOOKS"."TITLE" LIKE '%code%'
If that's not possible, what's the best workaround to get distinct authors in my scenario?
UPDATE
I should add that currently I'm using this formula in the Suppress details section:
{AUTHORS.ID} = previous({AUTHORS.ID})
The problem with this solution and also the group solution proposed by #Beth is that the query is the same and the DB return too much data for no reason. In both solutions the data is filtered/regrouped in Crystal Reports, not in the DB.
can you group by authors in your report and suppress the books.title details?
to group by author, in your report, under the Insert menu, select 'Group...' then select author.id in the first combo box and click OK. You'll notice your report has changed to introduce Group Header and Footer sections above and below the detail section. You can suppress the detail section and only the authors will print.
If you want only the authors to come across, you'll need to use a command sent to the data source with the SQL you want used, instead of using the tables directly like you are now.
You can create a command as your back-end with your parameter in it. You'll use that parameterized command instead of the tables you're using now. Try creating the command without the parameter first, then after you get that working, you can add your existing parameter into the command SQL.