JET ODBC SQL in excel, Case statements vs iif [closed] - sql

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am getting unrecognized keyword when when I am running a query to join two of my sheets in excel.
Error - 2147467259 - Unrecognized keyword WHEN
This error is due to case statements, they are not accepted in JET ODBC.
I am using JET ODBC and querying within excel sheets.
Can anyone help write a proper case statement using JET ODBC syntax, i can't get this to work.
iif ([stack$].[business_name] = 'GELP'
AND [overflow$].[level] = 'Package' THEN [overflow$].[identifier1]) END AS standardized_identifier,

CASE statements are not supported in SQL when hitting Excel sheets. You are using the JET ODBC/OLEDB provider in Windows which has limited syntax.
Instead use the IIF() function which is similar syntax to Excel's If().
As an example, your first CASE would look like:
iif([stack$].[managementl6description] = 'GLOBAL EQUITY-LINKED PRODUCTS', 'GELP' , iif([stack$].[managementl6description] = 'EQUITY MARKETS', 'EQUITY MARKETS', iif([stack$].[managementl6description] = 'FOREIGN EXCHANGE', 'FIC Foreign Exchange', NULL))) AS business_name

Related

What is a clean way to copy a SQL table with more than 1000 rows? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I know the question "How to copy table with more than 1000 rows" is already asked. I have read a lot about it and the different solutions like:
use export to excel and than import in new table
use UNION ALL (but not recommend)
use bulkreader
export to file and import
etc.
All the solutions sounding like a workaround. I am asking myself, is there no "official", clean way to do it?
Thank you.
Edit:
SELECT INTO was tried
INSERT INTO was tried
Using sql MS MGM studio
using HeidiSQL
Working on a MS SQL Server 13.0.4001.0
The cleanest and fastest solution with T-SQL would be into:
select *
into [destination table]
from [source table]
This will copy your data into a [destination table]. Be mindful of the remarks and limitations in the documentation regarding this keyword.

Syntax error (missing operator) in query expression ‘[Type]=5 And Left([Name],1)<>"~" OORDER BY [Name]’ [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have to create a list box control that contains all of the queries except for the system queries. Recall that system query names begin with the ~ character.
When I try to write SQL code in the row source (in the property sheet) for my frmQueries form I keep getting an error saying:
Syntax error (missing operator) in query expression:'[Type]=5 And Left([Name],1)<>"~" OORDER BY [Name]'
The code I entered is:
SELECT [Name] FROM MYSysObjects
WHERE [Type]=5 And Left([Name],1)<>"~"
OORDER BY [Name];
I am not sure why I am getting this error or how I can fix it.
OORDER should be ORDER, MYSysObjects should (presumably) be MSysObjects, and you can also replace Left([Name],1)<>"~" with [Name] not like "~*" (assuming MS Access instead of SQL Server).

How to use sp_depends for other database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Using SQL Server 2010
For updating the tables i am using following line
update database1_ab..table1
For sp_depends i am getting error as "Incorrect syntax near '.'"
sp_depends database1_ab..table1
How to use sp_depends for referring other database tables in current database
regardless, you need to put it in single quotes... ie
sp_depends 'database1_ab..table1'
or
sp_depends '[database1_ab]..[table1]'
You can call all the sp_ -procedures also in different database like this:
database1_ab..sp_depends table1

Why some rows can be inserted into and some cannot? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
When I use the Cashier table or some other tables that have small amounts of records the process proceeds and table is inserted into the external database. But when I change the cashier into the transaction database (400k+ records), Visual Studio reports an error near "Transaction" Help would be appreciated thanks.
Cashier Database (working)
Dim query As String = "select * into MyDatabase2.dbo.Cashier from bos_primary_db.dbo.Cashier"
Transaction Database (not working)
Dim query As String = "select * into MyDatabase2.dbo.Transaction from bos_primary_db.dbo.Transaction"
This is the error message:
Incorrect syntax near the keyword 'Transaction'
this is probably because Transaction is a reserved word in SQL.
Depending on your RDBMS (that you didn't specify), there are ways to "escape" it:
for Sql Server, you should wrap reserved words in square brackets:
select * into MyDatabase2.dbo.[Transaction] from bos_primary_db.dbo.[Transaction]
For MySql you should use an apostrophe:
select * into MyDatabase2.dbo.`Transaction` from bos_primary_db.dbo.`Transaction`
For Oracle you should use double quotes:
select * into MyDatabase2.dbo."Transaction" from bos_primary_db.dbo."Transaction"
Note: You should always try to avoid using reserved words. This link describes my favorite way of do it.

Syntax not valid on word 'ON' in SQL join statement [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to run an SQL SELECT statement which is running correctly in SQL Server Management Studio, but I keep receiving the error while trying to run the below code in Visual Basic/Studio:
In correct syntax near the word 'ON'
Code:
com = New SqlCommand("SELECT Member_Details.mMember_ID AS 'Unique ID', Member_Details.mFirst_Name + Member_Details.mLast_Name AS 'Name', CONVERT(varchar(10),Member_Details.mDoB,103) AS 'Date of Birth', Member_Details.mGender AS 'Gender', Rep_Group.rRep_Group_Name AS 'Rep Group'" & _
"FROM Member_Details" & _
"Join(Rep_Group) ON Member_Details.mRep_Group=Rep_Group.rRep_Group_ID", con)
The error message:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near the keyword 'ON'.
The SQL Statement does work without the Join statement, so I think I'm just formatting it wrong in Visual Studio.
Replace Join(Rep_Group) with Join Rep_Group in your code. JOIN is not a function :)