I have some c# which is using OleDb to query the Windows Search Index. The code mostly works but I have problems with the SQL
This is the folder structure -
C:\GitHub
C:\GitHub\abc
C:\Github\Test
C:\Github\Test\abc
And this is my SQL
SELECT Top 10 System.ItemPathDisplay FROM SYSTEMINDEX WHERE SCOPE='file:C:\GitHub' AND System.ItemPathDisplay LIKE '%abc%' AND System.Kind='Folder'";
The problem is the SQL only return C:\GitHub\abc and I want it to return all folders with abc in the path.
Related
Input Excel/CSV:
SQL Query: -
select 'WWW' as COLUMN_NAME,
(case when to_char (max(WWW)) = to_char(min(WWW)) and to_char(count(WWW)) = count(*) or to_char(max(WWW)) is null then 'same' else 'diff'end)as COMPARISION_VALUE, to_char(max(WWW))as TRANSACTION1, to_char(min(WWW))as TRANSACTION2
from ABC
where Book ='123' and UPDATE_DATE='01-JUN-18';
Note: - I am looking to put this SQL query in loop where first row will pass into the SQL query, then it will check the 2nd row, if the cell is blank it will consider the top most value and COLUMN_NAME will iterate as much we have specified. All the above 4 columns should be parameter.
***Output Console: -***
COLUMN_NAME COMPARISION_VALUE TRANSACTION1 TRANSACTION2
WWW same test test
Expected Output: - I want to save all the transaction in excel/CSV one by one
Please find the attached doc for complete Details
Your question concatenates Excel/CSV as through they're the same thing. They are not. Excel is a very different thing from CSV. Consequently they are two different requirements.
Excel is a binary format which makes it hard to integrate with SQL (although there are third party libraries which can help). CSV is open and text-based, so it's a lot simpler. With an external table you can query a CSV using SQL. Find out more.
As for output, you've tagged your question [plsqldeveloper]. That is the tag for the Allround Automations IDE, which already has excellent capabilities for exporting to Excel or CSV. If you are using that tool you should not reinvent its features. Oracle SQL Developer also already does this (and I suspect TOAD and most of the other IDEs out there do too).
I would like to use the GUI to find q column name in my sql query which has more than 300 columns
For example: I want to use GUI provided by SQL to find all the column names starting with VENDOR and hi-light them in order to make my operation easier..
I just want to use GUI
P.S: No query suggestions please, I am already aware of them (using like and all)
In MSQL Studio, use the Query Designer (Design Query In Editor...), paste your SQL, then use the name column in criteria pane to copy and paste in excel
UPDATE 2
Essentially, I'd like to pass the dataTable into SQL Server, but not actually "create it", just like a temporary thing using:
cmd.CommandText = "SELECT *
FROM table1
INNER JOIN dataTable
ON sample.name = dataTable.name"
How can I pass the dataTable from vb.net (.NET 2.0) to SQL Server in a similar fashion?
UPDATE 1
So I'm thinking maybe passing the data from the text file into a datatable and using that to compare against the SQL Server table? How would I go about doing that if at all possible?
ORIGINAL POST
I have a table in SQL Server 2012 (i.e., dbo.sample1) within the table there is a column that contains names (i.e., abc01, abc02, abc03, hijk01, hijk02...)
I ran some vb code to extract certain file names without extension from a directory on my machine (i.e., abc01, abc02...) that met certain conditions, these file names were saved on separate lines within a text file.
Is there any easier convenient way of linking ONLY the names on my text file to the ones on my table so as not to show any rows that are not on the text file? I figured I can sit and plug in a bunch of WHERE name = 'abc01'... but didn't really want to site there and do that for all of the names I have. But I'm not sure is this might even work correctly as I need to do an INNER JOIN on of 2 tables in the DB to the values in the text file.
If this is a long problem, then please point me in the right direction and I can research and move forward with it, but any help is greatly appreciated, thanks!
If the list of filenames is reasonable you can us the IN() clause:
SELECT * from XXX WHERE name IN ('abc01', 'abc02', 'abc03',...)
If the list is too long look into bulk copy up to a temp table to use with a JOIN.
I have a simple query but am running into problems using LIKE in VBA. My SQL string in VBA is:
stsql1 = "Select Top 25 data.* from data where data.Description Like ('*') "
When I run this sql string in my VBA code I get no records returned, but if I copy/paste the same string into a query in SQL View in MS Access, the query returns the values I expect. Is there a trick to using the "Like" syntax in VBA?
I can provide additional code and a small version of the database if that would help.
For SQL, the database engine will accept either single or double quotes as text delimiters. So either of these 2 WHERE clauses will work.
WHERE some_field Like '*'
WHERE some_field Like "*"
VBA however only accepts double quotes as text delimiters, so you would have to use the second form.
Two other points about your SELECT statement:
Select Top 25 data.* from data where data.Description Like ('*')
TOP [number] is arbitrary without an ORDER BY clause
You don't need parentheses surrounding your Like pattern ... you can use Like "*"
If your VBA code is using ADO with that SELECT statement, you must change the wild card character from * to % ...
WHERE data.Description Like '%'
In ADO/VBA, you have to use % instead of * as the wildcard. I ran into this a couple times in the past ....
Realize that there are at least 2 (yes two!) LIKE operators here.
One is the LIKE operator of VBA.
The other is the LIKE operator of the SQL of the database you are attached to.
The usual wildcards in SQL are % (for any # of any characters) and _ (for one of any character).
Know also that MS Access can open databases that aren't Access; it could be Microsoft SQL Server, or Oracle or IBM DB2. (BTW, the database that is normal for Access is called Microsoft JET.) You may be sheltered from that truth when you create a Query object in Access - in that circumstance, you are using JET SQL even when it's a linked table you are querying.
However, under VBA, when using either DAO or ADO, you're talking directly to whatever the database system happens to be, in which case you MUST use the SQL of that specific system.
OK, short answer: Use % like cularis said.
I can't add a comment, but I think it would be worth noting that you have to use % even if you are querying MS Access.
(example: Outlook VBA runs query on an Access database. The proper query is select * where user like '%bob%', even though this query would not work if plugged directly into an MS Access query).
is there a simple way to just output each record in a select statement to write to its own file?
for example, if you have the tsql query in sql server 2005,
select top 10 items, names + ':' + address from book
and you ended up with 10 text files with the individual name and addresses in each file.
is there a way to do this without writing an extensive spWriteStringToFile procedure? I'm hoping there is some kind of output setting or something in the select statement.
thanks in advance
SQL returns the result set first, there's no opportunity in there for writing records to specific files until afterwards.
Being SQL Server 2005, it's possible you could use a SQLCLR (.NET 2.0 code) function in a SQL statement without having to make a separate application.
In SSMS, you can do a results to file, but that wouldnt split each record out into its own file. I pretty sure you cannot do this out of the box, so it sounds like you will be rolling your own solution.
You'd do this in some client, be it Java, VBA or SSIS typically.