Visual studio query builder using filter - visual-studio-2010

hi i have made a query but it is not giving any results, i am using 3 parameters cri,d1 and d2
i want to give values at run time, but when this query is executed no data is displayed even though i am giving correct input
SELECT [Name Of District],
[ANC Id],
[Gram Panchayat or Village],
[Name Of Subcenter],
[Name Of PHC],
[Name Of Cluster],
[ANC Name],
EDD,
[2nd ANC],
[3rd ANC],
[4th ANC],
[TT Bosters]
FROM [ANC Data]
WHERE ('# cri' BETWEEN '# d1' AND '# d2')

You can try to use the SQL Server Profiler tool to inspect the real SELECT statement with real WHERE parameters’ values.
Just execute the same SELECT statement within the SQL Server Management Studio environment and check whether there is any data records satisfied to the SELECT query.

Related

Oracle SQL Developer How to export via a command line the result of a SQL script?

This is my first question on StackOverflow (but not the first question I asked to myself on Oracle SQL Developer :p)
My needs :
I first tried to do all my works exclusively on Oracle SQL Dev but it asks to much ressources to be done.
In consequences, I decided to only export all the data I need and then import all in R and do my work on it.
Finally, it takes about 2 minutes to do the job :D
My problem is :
I run about 10 different SQL script which are really simple. Please find below two of them :
select japolip_wnupo wnupo,japolip_socpo socpo,japolip_jasccdp_winag winag,japolip_wnpro wnpro,jaagenp_ainag,jaagenp_nomag
from sunapicf.japolip japolip
left join sunapicf.jaagenp jaagenp on jaagenp_winag = japolip_jasccdp_winag
;
select distinct socpr socpo,jaagenp.jaagenp_winag winag,JACRCFP.JACRCFP_wnpro wnpro,jaagenp_ainag,jaagenp_nomag
from sunapicp.JACRCFP JACRCFP
left join
(
select japrodp_wnpro,socpr
from sunapicp.japrodp japrodp
cross join xmltable('//JAPRODP' passing xmltype(japrodp.ficxml) columns SOCPR)
) japrodp on japrodp.japrodp_wnpro = JACRCFP.JACRCFP_wnpro
left join sunapicf.jaagenp jaagenp on jaagenp.jaagenp_winag = jacrcfp.jacrcfp_winit
;
Then I have to launch the Export function for every results, change the formatting and the type of file to be delivered to .dsv (just to have the right comma :D), and also change the folder directory and the name.
It is too much repetitive and can generate some mistakes.
That's why I would like to add a command line where I would specify the folder directory, the name, the formatting and what so ever.
Do you have any information about that ?
Thank you very much.
I did not try anything because I don't have any idea to try.
I tried to connect R to Oracle but I guess I have to pay for it (and the company does not want to :D).
Using SQLcl is definitely the way to go. Build a script (or set of scripts) that run all of the queries that you want to export data into CSV files. Below is an example script that will connect to the database, set formatting, generate the files then disconnect.
The script would get launched with a command like this:
sql /nolog #start_export.sql
start_export.sql example contents:
--Connect to the database
connect <username>/<password>#<TNSalias>
--Set format to CSV for results from SELECT statements
set sqlformat csv;
--Turn off the number of rows that get returned by the select
set feedback off;
--Create 1st report
spool report1.csv
select japolip_wnupo wnupo,japolip_socpo socpo,japolip_jasccdp_winag winag,japolip_wnpro wnpro,jaagenp_ainag,jaagenp_nomag
from sunapicf.japolip japolip
left join sunapicf.jaagenp jaagenp on jaagenp_winag = japolip_jasccdp_winag;
--Create 2nd report
spool report2.csv
select distinct socpr socpo,jaagenp.jaagenp_winag winag,JACRCFP.JACRCFP_wnpro wnpro,jaagenp_ainag,jaagenp_nomag
from sunapicp.JACRCFP JACRCFP
left join
(
select japrodp_wnpro,socpr
from sunapicp.japrodp japrodp
cross join xmltable('//JAPRODP' passing xmltype(japrodp.ficxml) columns SOCPR)
) japrodp on japrodp.japrodp_wnpro = JACRCFP.JACRCFP_wnpro
left join sunapicf.jaagenp jaagenp on jaagenp.jaagenp_winag = jacrcfp.jacrcfp_winit;
--Disconnect
exit

Different output script generated by linq to sql 2016 Express/Standard edition vs developer edition

I'm developing desktop application (WinForm) using vb.net and using LINQ to access the database (SQLSERVER 2016)
I have 2 instance database identical DB(same structure and data).
- SQLEXPRESS2016 (Express edition)
- SQLSERVER2016 (Developer edition)
But why I getting significant Different time execution and different schema execution plan also? The sql script generated by LINQ??
dim myResult = (from i in myDataContext.ItemMaster _
Where i.IsActive _
Order by m.ItemNumber).AsQueryable
dim count = myResult.Count()
I profiling the query generated by linq by SQL Server profiling, and myResult.Count() will generated the script (in this case the script is same between dev and standard/express):
Select Count(1) AS [value]
FROM( Select TOP (1000) NULL AS [EMPTY]
FROM ITEM_MASTER as [t0] WHERE IS_Active = 1
ORDER BY [t0].[ItemNumber]
)AS [t1]
My Question are:
1. Why in some cases the query was different between
Express/Standard edition and Developer edition? (The DB structure and data is same, just different version)
one will generated SELECT TOP (1)..., the other will SELECT TOP (2) ....
Why The execution time different is significant.
dev = 0.xx seconds
std/express = 8s econds.
it should not a big deal, since the number of rows about 10,000 something
Why the execution plan also different? std/express seems more complicated schema and some index is missing.
screenshot sql dev vs express/standard
It solved by adding NOEXPAND hint keyword.
See original answer here:
https://social.msdn.microsoft.com/Forums/en-US/b095ce80-6b19-45a5-9a31-4532fcd8af83/different-output-script-generated-by-linq-to-sql-2016-expressstandard-edition-vs-developer-edition?forum=sqlnetfx
credit to: Yuvraj Singh Bais

Get a query and it's parameters values from VS in debugger for calling into SQL

Is there a way by not manually copy each statement like a SELECT or stored procedure and it's parameters values in debugger mode for executing it into SQL environment? I'm thinking of a box displaying the entire statement in Visual Studio and just copy it's content.
it is inconvenient to copy parameter's values for a query that has 20 parameters by checking each argument.
With a profiler you can obtain the exact command executed in the DB. For example, using "SQL Server 2016 Profiler" you get the following for a SQL query with two parameters:
exec sp_executesql N'SELECT * FROM Orders WHERE customerId=#Param1 AND productId=#Param2',N'#Param1 int,#Param2 int',#Param1=30,#Param2=10
This command can be executed in SSMS.

Why does DENSE_RANK cause an error when used in SSIS query against ORACLE using OLE DB?

This query:
SELECT
DENSE_RANK() OVER (PARTITION BY UPPER(ANUMID), UPPER(PRODNUMID) ORDER BY DATE_ADDED ASC) AS DRANK
, ANUMID
, PRODNUMID
, STATUS_FDATE
, STATUS_XDATE
, ROWSTATUS
FROM
AGCOMN
The query ranks the rows in each group of ANUMID, PRODNUMID by DATE_ADDED from 1 to x. In a subsequent query the DRANK=1 gets the most recent row added.
This query works in ORACLE SQL Developer, and on my local machine SSIS environment, and on the SSIS OLE DB Source preview on the TEST server, but does NOT work when the package is ran.
ERROR:
[OLE DB Source 1 [677]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E14.
An OLE DB record is available. Source: "OraOLEDB" Hresult: 0x80040E14 Description: "ORA-00936: missing expression".
Environment:
Local - Windows XP, SQL BIDS 2008
Test - Windows7, SQL/BIDS 2008
I have since rewrote and simplified the query, grabbing the data into a temp table then use SQL server to rank and pare down the number of records.
Any ideas on finding the root cause of the SQL not working in the first place? And why the preview would work but running the package does not?
I have discovered the problem. There were embedded comments using the double dash in the middle of the SQL. When I removed them, the query worked. I removed them in my original posting when I "cleaned up" the query to post it to this public forum.
This is true in both 32-bit and 64-bit mode. I also removed the AS from the AS DRANK phrase, which did not make a difference in this case. Thanks for the ideas.

Oracle Execution Plan

I am using Oracle 11g and Toad for Oracle. How can I display execution plan for queries?
In Sql server management studio execution plan can be displayed as graphical format. Is there any functionality/tool like that on Toad for oracle?
CTRL-E
Make sure you've ended the query with a semi-colon (and the query above)
Edit:
You need to set-up the TOAD plan table for use. If you think it's already setup on your DB then you may just need to be granted access. Alternatively in my slightly older version of TOAD it's under:
Database --> Administer --> Server Side Objects Wizard. From here you can create the plan table(s) in a schema that you choose.
You should create the PLAN_TABLE using a script provided by Oracle
which is named UTLXPLAN.SQL and is located in one of the installation folders
on the database server.
Then, you should use the EXPLAIN PLAN statement for generating a plan for a SQL statement, like this:
EXPLAIN PLAN SET STATEMENT_ID = 'your_identifier_for_this_plan'
FOR
... your statement ... ;
Then, you can use either a select from PLAN_TABLE (usually using a hierarchical query) or the DBMS_XPLAN.DISPLAY_PLAN procedure to display the plan.
In the same folder where the UTLXPLAN.SQL file is located, there usually exist
examples of using this procedure.
Also, in SQL*PLUS you can use the SET AUTOTRACE feature.
For TOAD FOR ORACLE
this helped me How do I view the Explain Plan in Oracle Sql developer?, I just write what they did in sql developer and wrote in the toad editor and then execute.
Example
explain plan for select field1, field2 from TABLE_NAME;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
Check that all queries end with a semicolon, put the cursor on the query you want to analyze and hit CTRL-E.
The first time you could get a popup that asks for the name of the plan table, it suggests TOAD_PLAN_TABLE but it's better to use the standard Oracle table PLAN_TABLE that should be already available. So enter PLAN_TABLE in place of TOAD_PLAN_TABLE (do not specify a schema) and hit OK. You should get a message saying that the object already exists: hit OK again to acknowledge it. Now try CTRL-E again and you'll get the explain plan.
To view/change the currently configured plan table name go to menu "View / Toad Options / Oracle General".

Resources