SQL Server "n*" wildcard in contains problem - sql

I have a problem with SQL Server contains.
I have 2 data in some table, the code of data is "CJK-7123" and "CJK-7890".
When I use SQL Server contains like this "contains((table.code),'"n*"')" in my select query, those of two data is still showing in my query, even though the code doesn't contain n character.

Related

Why do some string fields only have a single character when using Oracle heterogeneous services to pull view from SQL Server?

I have confirmed that the view returns the correct data when on the SQL Server. But when pulling the raw view through Oracle some of the string columns only contain 1 character for each record, while other columns are fully populated.
Does anyone know what could cause this issue?
The fields that had cutoff characters were NVARCHAR(50). Apparently, Oracle does not pull NVARCHARs correctly from SQL Server. Casting them as VARCHAR(50) in the SQL Server view solved the problem.

SQL - Remove trailing " where it exists in column

I have a SQL table that will be receiving new data daily. At times, the data in 3 of the 10 columns contains a trailing double quote ("). Is there an easy way to remove that final quote where it exists? Whatever the query or procedure is, I will be running it from either python or vba, depending on where this project goes in the next 2 weeks - but I think if I can get it to work from Microsoft SQL Server Mgmt Studio, I'll be able to modify for either one.
Try:
UPDATE table
SET column = left(column,length(column)-1)
WHERE column like '%"'

SQL Server - Syntax around UNION and USE functions

have a series of databases on the same server which i am wishing to query. I am using the same code to query the database and would like the results to appear in a single list.
I am using 'USE' to specify which database to query, followed by creating some temporary tables to group my data, before using a final SELECT statement to bring together all the data from the database.
I am then using UNION, followed by a second USE command for the next database and so on.
SQL Server is showing a syntax error on the word 'UNION' but does not give any assistance as to the source of the problem.
Is it possible that I am missing a character. At present I am not using ( or ) anywhere.
The USE statement just redirects your session to connect to a different database on the same instance, you don't actually need to switch from database to database in this matter (there are a few rare exceptions tho).
Use the 3 part notation to join your result sets. You can do this while being connected to any database.
SELECT
SomeColumn = T.SomeColumn
FROM
FirstDatabase.Schema.TableName AS T
UNION ALL
SELECT
SomeColumn = T.SomeColumn
FROM
SecondDatabase.Schema.YetAnotherTable AS T
The engine will automatically check for your login's users on each database and validate your permissions on the underlying tables or views.
UNION adds result sets together, you can't issue another operation (like USE) other than SELECT between UNION.
You should use the database names before the table name:
SELECT valueFromBase1
FROM `database1`.`table1`
WHERE ...
UNION
SELECT valueFromBase2
FROM `database2`.`table2`
WHERE ...

invalid data is getting inserted in table in sql server database

I faced a situation and also searched for it in the internet but could not be able to get any solution.
Problem
My sql server table has 15000 records. It has several columns.
Among all the records, the 'Email ID' column of one record is storing value along with an unidentified character at the beginning. (Please refer to picture attached)
What I want
I want to get rid of that character using sql query. I am using sql server 2012 version.
I tried with 'replace()' and 'patindex()'. I even tried 'stuff' function.
But, its not working. Instead, when I am fetching the data using query, it is showing that typical character.
Please help me with some ideas. If I need to do some settings in database or table, I am ready for that.
Thanks.

Create delimited string from a row in stored procedure with unknown number of elements

Using SQL Server 2000 and Microsoft SQL Server MS is there a way to create a delimited string based upon an unknown number of columns per row?
I'm pulling one row at a time from different tables and am going to store them in a column in another table.
A simple SQL query can't do anything like that. You need to specify the fields you are concatenating.
The only method that I'm aware of is to dynamincally build a query for each table.
I don't recall the structure of MSSQL2000, so I won't try to give an exact example, maybe someone else can. But there -are- system tables that contain table defintions. By parsing the contents of those system tables you can dynamically build the necessary query for each source data table.
TSQLthat writes TSQL, however, can be a bit tricky to debug and maintain :) So be careful how you structure everything...
Dems.
EDIT:
Or just do it in your client application.