Query in VB2010 based on indian language - sql

I am developing a application based on native Indian language. I have to search the database column (in native language) student name in native language. Can anybody help me to solve this issue
my query builder code looks like this and shows syntax error
SELECT [ಕ್ರಮ ಸಂಖ್ಯೆ], [ವಿದ್ಯಾರ್ಥಿಯ ಹೆಸರು] AS Name, [ರಜಿಸ್ಟರ್ ಸಂಖ್ಯೆ], [ಡೈಸ್ ಸಂಖ್ಯೆ], [ವರ್ಗ], [ಕನ್ನಡ], [ಇಂಗ್ಲೀಷ], [ಹಿಂದಿ], [ಗಣಿತ], [ವಿಜ್ಞಾನ], [ಸಮಾಜ ವಿಜ್ಞಾನ], [ದೈಹಿಕ ಶಿಕ್ಷಣ], [ಒಟ್ಟು ಅಂಕಗಳು], [ಶೇಕಡಾ], [ಶ್ರೇಣಿ], [ಒಟ್ಟು ಅಂಕಗಳು ಅಕ್ಷರದಲ್ಲಿ], [ಲ,ಕ/ಕಲಾ ಶಿಕ್ಷಣ], [ಕಂಪ್ಯೂಟರ ಶಿಕ್ಷಣ], [ಫಲಿತಾಂಶ]
FROM Table11
WHERE ವಿದ್ಯಾರ್ಥಿಯ ಹೆಸರುCollate Indic_General_100_CI_AI LIKE N '%ಮ%'

I notice a couple things right off. Because the field in your where clause has a space in it... you have to put delimiters around it. Also, you don't seem to have a space between your field and the Collate keyword... that is necessary. Lastly, you can not have a space between the N and the apostrophe to specify a nvarchar string literal. So try a where clause like this:
WHERE [ವಿದ್ಯಾರ್ಥಿಯ ಹೆಸರು] Collate Indic_General_100_CI_AI LIKE N'%ಮ%'
If you are still getting an error, it could be that your field [ವಿದ್ಯಾರ್ಥಿಯ ಹೆಸರು] is not of a unicode string type. Make sure the field is defined as nvarchar, nchar,...etc.
From your comment it appears that you are querying a MS Access database. The above is for querying a SQL Server Engine. The where clause for access would look like this:
WHERE [ವಿದ್ಯಾರ್ಥಿಯ ಹೆಸರು] LIKE '*ಮ*'

Related

Querying full and sub-strings via multi-valued parameter using SQL

I am building a report with Microsoft SSRS (2012) having a multi-value parameter #parCode for the user to filter for certain codes. This works perfectly fine. Generally, my query looks like this:
SELECT ...
FROM ...
WHERE
TblCode.Code IN (#Code)
ORDER BY...
The codes are of following type (just an excerpt):
C73.0
C73.1
...
C79.0
C79.1
C79.2
Now, in additon to filtering for multiple of these codes I would like to als be able to filter for sub-strings of the codes. Meaning, when the user enters (Example 1)
C79
for #parCodes The output should be
C79.0
C79.1
C79.2
So eventually the user should be able to enter (Example 2)
C73.0
C79
for #parCodes and the output would be
C73.0
C79.0
C79.1
C79.2
I managed to implement both functionalities seperately, so either filtering for multiple "complete" codes or filterting for sub-string of code, but not both simultaneously.
I tried to do something like
...
WHERE
TblCode.Code IN (#parCode +'%')
ORDER BY...
but this screws up the Example 2. On the other hand, if I try to work with LIKE or = instead of IN statement, then I won't be able to make the parameter multi-valued.
Does anyone have an idea how to realize such functionality or whether IN statement pared with multi-valued parameters simply doesn't allow for it?
Thank you very much!
Assuming you are using SQL server
WHERE (
TblCode.Code IN (#parCode)
OR
CASE
WHEN CHARINDEX('.', Code)>0 THEN LEFT(TblCode.Code, CHARINDEX('.', TblCode.Code)-1)
ELSE TblCode.Code
END IN (#parCode)
)
The first clause makes exact match so for your example matches C73.0
The second clause matches characters before the dot character so it would get values C79.0, C79.1, C79.2 etc
Warning: Filtering using expressions would invalidate the use of an index on TblCode.Code

Is there a more efficient way to parse a fixed txt file in Access than using queries?

I have a few large fixed with text files that have multiple specification formats in them. I need to parse out the txt files based on a character with a set location in the file. That character can have a different position in the file.
I have written queries for each of the different specifications (95 of them) with the start position and length hard coded into the query using the mid() function with a WHERE() function to filter the [Record Identifier] from the specification. As you can see below the 2 specifications in the WHERE() function have different placements in the txt file.
\\\
SELECT Mid([AllData],1,5) AS PlanNumber, Mid([AllData],6,4) AS Spaces1, Mid([AllData],10,3) AS Filler1, Mid([AllData],13,11) AS SSN, Mid([AllData],24,1) AS AccountIdentifier, Mid([AllData],25,5) AS Filler2, Mid([AllData],30,2) AS RecordIdentifier, Mid([AllData],32,1) AS FieldType, Mid([AllData],33,4) AS Filler3, Mid([AllData],37,8) AS HireDate, Mid([AllData],45,8) AS ParticipationDate, Mid([AllData],53,8) AS VestinDate, Mid([AllData],61,8) AS DateOfBirth, Mid([AllData],77,1) AS Spaces2, Mid([AllData],78,1) AS Reserved1, Mid([AllData],79,1) AS Reserved2, Mid([AllData],80,1) AS Spaces3
FROM TBL_Company1
WHERE (((Mid([AllData],30,2))="02") AND ((Mid([AllData],32,1))="D"));
\\\
Or
\\\
SELECT Mid([AllData],1,5) AS PlanNumber, Mid([AllData],6,4) AS Spaces1, Mid([AllData],10,3) AS Filler1, Mid([AllData],13,11) AS SSN, Mid([AllData],24,1) AS AccountIdentifier, Mid([AllData],25,7) AS RecordIdentifier, Mid([AllData],32,22) AS StreetAddressForBank, Mid([AllData],54,20) AS CityForBank, Mid([AllData],74,2) AS StateForBank, Mid([AllData],76,5) AS ZipCodeForBank
FROM TBL_Company1
WHERE (((Mid([AllData],25,7))="49EFTAD"));
\\\
Is there a way to Parse out this without having to hard code every position and length into the code?
I was thinking of having a table with all of the specifications in it and have an import function look to the specification table and parse out the data accordingly to a new table or maybe something else.
What I have done is not very scalable and if the format changes a little I would have to go back to each query to change it.
Any Help is greatly appreciated
I think in your situation, I'd want to be able to generate the SQL statement dynamically, as you suggest.
I'd have a table something like:
Format#,Position,OutColName,FromPos,Length,WhereValue
1,1,"PlanNumber",1,5,
1,2,"Spaces1",6,4,
...
1,n,,30,2,"02"
1,n+1,,32,1"D"
and then some VBA to process it and build and execute the SQL string(s). The SELECT clause entries would be recognized by having a value in the OutColName field and WHERE clause entries by values in the the WhereValue column.
Of course this is only more "efficient" in the sense that it's a bit easier to code up new formats or fix/modify existing ones.

MS Query Excel to Access reserved word, misspelling or punctuation error

I am new to SQL and I am trying to link my excel workbook (2010) to an Access database table (2010) using MS Query to return some summary statistics on our Fleet. I have a parameter for the month which is located in a cell in the excel workbook.
The code I have is below and I get the error message
The SELECT statement includes a reserved word or an argument name that
is misspelled or missing, or the punctuation is incorrect.
I have used the parameter for more simple information and it works perfectly, however, this code seems to be missing something.
SELECT tbl_FLEET_HISTORY.`Type`,
Sum(tbl_FLEET_HISTORY.`Number Railcars`) AS `QTY_Wagons`
Sum(tbl_FLEET_HISTORY.`Number of Platforms: loading units`) AS `QTY_Platforms`
Sum(tbl_FLEET_HISTORY.`Days Leased in Month`) AS `Days_Leased`
Sum(tbl_FLEET_HISTORY.`Days Available`) AS `Days_Available`
Sum(tbl_FLEET_HISTORY.`Daily Rate`) AS `Daily_Rate`
FROM tbl_FLEET_HISTORY tbl_FLEET_HISTORY
WHERE (tbl_FLEET_HISTORY.`Month`=?)
and (tbl_FLEET_HISTORY.`Leased During Month`=`Yes`)
GROUP BY tbl_FLEET_HISTORY.`Type`
I have run through a lot of the answers to this topic but I have not been able to resolve the issue.
I would really appreciate any assistance. If there is any additional information needed please let me know.
In MS Access, the query would look more like:
SELECT fh.Type,
SUM(fh.[Number Railcars]) AS QTY_Wagons,
SUM(fh.[Number of Platforms: loading units]) AS QTY_Platforms,
SUM(fh.[Days Leased in Month]) AS Days_Leased,
SUM(fh.[Days Available]) AS Days_Available,
SUM(fh.[Daily Rate]) AS Daily_Rate
FROM tbl_FLEET_HISTORY as fh
WHERE fh.Month = ? AND
fh.Leased During Month = "Yes"
GROUP BY fh.type;
Notes:
String constants are delimited by double quotes in MS Access.
Backticks are not used at all. Column names are escaped using square braces.
You do not need to escape the aliases you are assigning.
You need commas between the expressions in the SELECT.

SQL wildcards via Ruby

I am trying to use a wildcard or regular expression to give some leeway with user input in retrieving information from a database in a simple library catalog program, written in Ruby.
The code in question (which currently works if there is an exact match):
puts "Enter the title of the book"
title = gets.chomp
book = $db.execute("SELECT * FROM books WHERE title LIKE ?", title).first
puts %Q{Title:#{book['title']}
Author:#{book['auth_first']} #{book['auth_last']}
Country:#{book['country']}}
I am using SQLite 3. In the SQLite terminal I can enter:
SELECT * FROM books WHERE title LIKE 'Moby%'
or
SELECT * FROM books WHERE title LIKE "Moby%"
and get (assuming there's a proper entry):
Title: Moby-Dick
Author: Herman Melville
Country: USA
I can't figure out any corresponding way of doing this in my Ruby program.
Is it not possible to use the SQL % wildcard character in this context? If so, do I need to use a Ruby regular expression here? What is a good way of handling this?
(Even putting the ? in single quotes ('?') will cause it to no longer work in the program.)
Any help is greatly appreciated.
(Note: I am essentially just trying to modify the sample code from chapter 9 of Beginning Ruby (Peter Cooper).)
The pattern you give to SQL's LIKE is just a string with optional pattern characters. That means that you can build the pattern in Ruby:
$db.execute("SELECT * FROM books WHERE title LIKE ?", "%#{title}%")
or do the string work in SQL:
$db.execute("SELECT * FROM books WHERE title LIKE '%' || ? || '%'", title)
Note that the case sensitivity of LIKE is database dependent but SQLite's is case insensitive so you don't have to worry about that until you try to switch database. Different databases have different ways of dealing with this, some have a case insensitive LIKE, some have a separate ILIKE case insensitive version of LIKE, and some make you normalize the case yourself.

SQL Server 2005 - Incorrect syntax near '/'

Here's a very easy question for someone :)
Trying to update an SQL column with the following:
UPDATE [NameOfTable]
SET [HtmlContent] = 'a href="/sell-your-boat/"'
WHERE HtmlID = 123456
But am getting the following error message: Incorrect syntax near '/'.
I know it's because I need to escape the / character but hitting my head against the wall trying to find the answer because I am aware it's probably very simple!
Thank you
You don't need to escape slashes in a string in SQL. The only chracter that you need to escape is apostrophe (').
There is nothing wrong with the query that you are showing, so the only explanation is that the code that you are actually running does not look like that.
It doesn't make sense to have HTML-encoded quotation marks around a href attribute, so my guess is that the HTML code actually looks something like this:
<a href='/sell-your-boat/'>
Any apostrophes in the text would have to be encoded as double apostrophes when you put it in a string literal in the SQL code.
I don't know where the query is executed from, but a parameterised query would be preferrable if possible, as then you don't have to escape the text yourself, you just assign the text to the property value.
Like all the comments above, youd don't need to escape the /
I just did a quick sql test in sql server 2005 and didn't get an error message (see below)
We'll probably need more information than what you provided. Are you running this in Management studio, or is this sql being called in a .NET application, etc...
create table test (htmlid int, htmlcontent varchar(516))
insert into test select 123456 as htmlid, 'test' as htmlcontent
update test
set htmlcontent = 'a href="/sell-your-boat/"'
where htmlid = 123456
select * from test where htmlid = 123456
drop table test
my output
123456 a href="/sell-your-boat/"