How To Used ' Character In Sql Query

May 2, 2008

begin
SET @STR='INSERT INTO tbl_Level1' + '(' + @columnName + ',orgID' + ')' + 'Values' + '(' + @Level1Name + ',' + @orgID + ')'

EXEC @STR


ERROR :- Conversion failed when converting the varchar value 'INSERT INTO tbl_Level1 (Level1Name_HIN,orgID ) Values (@Level1Name,' to data type int. pls help me out


Yaman

View 10 Replies


ADVERTISEMENT

Newline Character In Query

Feb 28, 2002

Can I use a newline character in my query? I want to dynamically generate a statement, split on several lines. Simple example:

declare @cmd varchar(100)
select @cmd = 'select user_name(), getdate()'
select @cmd

The output will be: select user_name(), getdate()

Can I use something like this:
declare @cmd varchar(100)
select @cmd = 'select user_name(), getdate()'
select @cmd

so as to get an output like this:
select user_name(),
getdate()

Thanks.

View 1 Replies View Related

Ascii Character Query

Mar 18, 2008

item custclass totalcustclass
-------------------------
06-5841 INST-CLINPRAC 1
06-5841 INST-MKT/MEDIA 2
06-5841 PROGRAM 1
06-5841 STANDARD 4
06-5845 STANDARD 1
AX-048 INST-MKT/MEDIA 4
KT-048 PROGRAM 2
KT-048 STANDARD 4

i want condition like if item is starting with number then totalcustclass whcih is count(*) remain same giving correct results...but if item startign with ascii character then totalcustclass r getting double so i have to /2..

i want results:

item custclass totalcustclass
-------------------------
06-5841 INST-CLINPRAC 1
06-5841 INST-MKT/MEDIA 2
06-5841 PROGRAM 1
06-5841 STANDARD 4
06-5845 STANDARD 1
AX-048 INST-MKT/MEDIA 2
KT-048 PROGRAM 1
KT-048 STANDARD 2

select
item, custclass,

case when item is <ascii> then count(custclass)/2
else count(custclass)
as totalcustclass

from itemcustclass

can anyone tell me what condition will come in case?

thanks for help.

View 2 Replies View Related

Simple Excluding Of Character Query

Feb 25, 2005

i have a field with 2 characters(many of them ) and spaced inbetween them
which are codes for something


ie XA OX YY BY CY DY XC XD OE In any or all combination

i want to make a count of rows which contains BOTH XA
BUT DOES NOT CONTAIN any one or all of XC,XD & OE

SO I write the query
select count(colname)
from tablename
where colname LIKE ('%XA%')
AND colname NOT LIKE ('%XC%')
OR colname NOT LIKE ('%XD%')
OR colname NOT LIKE ('%OE%')
')

iS this correct
why then it does not exclude the XC,XD,OE

is there a better way ?

View 14 Replies View Related

Single Unique Character Query

Oct 27, 2014

I have a huge database (20 columns and 56000 lines) and I need a query that can return each single unique character from all this database.

For example if character "a" appears at least one time in this database I need this query to show it to me.

View 2 Replies View Related

Get Specific Range Of Character Through Query

Mar 19, 2008

Hi !
i have a query like select top 3 column1 from table 1 order by Id desc

here the column1 is of varchar(512) data type but i want to get only first 250 chars of it and if they are less than 250 then get the whole range

plz let me know how it is possible throguh query or any other way

Regards,

View 1 Replies View Related

T-SQL (SS2K8) :: Find String Before Character When Character Appears Multiple Times

May 17, 2015

I have a table that contains file paths as

ServernamefolderAfilenameA
ServernameFolderBFilenameB

and I need a query to return

ServernamefolderA
ServernameFolderB

I tried

SELECT DISTINCT left(Source, charindex('', Source)- 0) AS String
FROM Table

But that removes everything after the first and I need it to return all data before the last

View 5 Replies View Related

T-SQL (SS2K8) :: Replace Multiple Occurrences Of Same Character With Single Character

Aug 6, 2015

I have the following scenario, The contents of main file are like :

ServerCentral|||||forum|||||||||||||||is||||||the||best
so||||||be|||||on||||||||||||||||||||||||||||||||||||||||||||it

And I need the output in the following form:

ServerCentral=forum=is=the=best
so=be=on=it

The logic being that multiple and consecutive occurrences of the special character, here - pipe , should be replaced by a single special character.

View 5 Replies View Related

SQL Server 2012 :: Tab Character In Query Results

Jul 9, 2015

I am getting a tab character at the end of my query fields, been trying various things to fix, such as using the replace function below but still i get the tabs!

select CAST(REPLACE(NAMEALIAS,CHAR(9),'')AS CHAR(40)) + ',' as PRODNAME,
CAST(REPLACE(ISNULL(GLOBALTRADEITEMNUMBER,0),CHAR(9),'')AS CHAR(18))as EANNO,LTRIM(cast(ISNULL(GLOBALTRADEITEMNUMBER,0) as char(18))) as KONSEAN
,LTRIM(CAST(I.ITEMID AS CHAR(8))) AS PRODCODE,'00' from INVENTTABLE I
LEFT JOIN INVENTITEMGROUPITEM IG ON I.ITEMID = IG.ITEMID

[Code] ....

Results:
Gießanzeiger groß ,04260376730475 04260376730475 730475 00
Gießanzeiger klein , 04260376730352 04260376730352 730468 00
Gießanzeiger klein , 04260376730468 04260376730468 730468 00

View 9 Replies View Related

Turkish Character I Creates Problem In My Query

Oct 9, 2006

Dear all,

i am using SQL server for turkish language and i have a problem with turkish character "i". Whenever "i" comes in any word of query it gives wrong result. It also not able to recognize the small and capital "i" of turkish.

View 1 Replies View Related

Select Part Of Character String Based On A Character

Apr 15, 2004

I have data in a column that starts with 1-4 characters followed by a dash then followed by an number of characters (ex: EU-Surgery).

How do I select everything to the right of the dash when the number of characters to the left of the dash varies?

View 3 Replies View Related

Character String Query Doesn't Fill Dataset

Mar 15, 2007

I'm working in a ASP.NET 2.0 application with a SQL Server 2000 database on the back end.  I have a strongly typed dataset in the application that calls a stored procedure for the select.  I'm having trouble filling the dataset at runtime though.
I am trying to use a character string query because I setup different columns to be pulled from a table each time and in a different order so my T-SQL looks like this:
set @FullQuery = 'Select ' + @FieldsinOrder + ' from tblExample'exec (@FullQuery)
This works fine in query analyzer.  The results return and display correctly.  However, when I run the application, the dataset does not get filled.  It is like the results do not output to the application.
If I change the query to be a normal select it works.  For example:
select * from tblEmample
That works fine.  What is it about a select query setup as a character string and then executed that ASP.NET doesn't like?

View 1 Replies View Related

What Collation To Have Ascii Character 160 Display In Query Results

Feb 11, 2008

I have an issue with some data that has a leading ASCII char 160 (the "a" with the accent mark) but it shows in query results as a space.


... where customername like char(160) + '%'

returns 2 rows but shows the customer name with a leading space. How would I change the collation or do otherwise to get this character to display correctly in the results?

Thanks!

-Dave

View 6 Replies View Related

Return Left-most Character From 8 Character String

Oct 1, 2014

I'd like to return the left-most character from an 8 character string & the third from the left character too.

Like this ABC00123 returns AC

$query = "SELECT LEFT(uninum,3), RIGHT(uninum,5), clmarea, Date FROM tblunimov";
$result = mysql_query($query) or die(mysql_error());

echo "<div class='tblstyle1'>";
echo "<table class='tblstyle1'>";
echo "<tr><th>ini</th><th>item</th><th>area</th><th>date</th></tr>";
while($row = mysql_fetch_array($result)){

[Code] ....

View 5 Replies View Related

Read Chinese Character From SQL(SQL Server 2005) Database Table Column And Display Chinese Character

Feb 1, 2008

Hi!

I have a table like this below and it doesn't only contain English Names but it also contain Chinese Name.
CREATE TABLE Names
(FirstName NVARCHAR (50),
LastName NVARCHAR (50));
I tried to view the column using SQL Query Analyzer, It didn't display Chinese Character.
I know that SQL Server 2005 is using UCS-2 Encoding and Chinese Character uses Double Byte Character Set (DBCS) Encoding.
I want to read the FirstName and LastName columns and display in Window Form Data Grid and ASP.NET Grid View.
I tried to use this code below and it didn't work. It convert some of the English Name to Chinese Character and it display the chinese character and some still in the original unreadable characters.
Does anybody know how to read those character from SQL Table and display the correct Chinese Character without converting the English Name into Chinese also?
Thanks

int codePage = 950;
StringBuilder message = new StringBuilder();
Encoding targetEncoding = Encoding.GetEncoding(codePage);
byte[] encodedChars= targetEncoding.GetBytes(str);
.
message.AppendLine("Byte representation of '" + str + "' in Code Page '" + codePage + "':");
for (int i = 0; i < encodedChars.Length; i++)
{
message.Append("Byte " + i + ": " + encodedChars);
}

message.AppendLine(" RESULT : " + System.Text.Encoding.Unicode.GetString(encodedChars));
Console.Writeline(message.ToString());

View 1 Replies View Related

Character Set

Oct 6, 2000

Hi,
Anytime I BCP data from a table containing characters like ö it gets muddled up when I look at it in the text file. The code page of the NT OS is 850 and the character is included in it. Why is the character changed during the BCP ?

Bob

View 1 Replies View Related

The ' Character

Nov 16, 2006

Hello all.

Ok this is going to be a little hard to describe but here goes

I have a table within which one column is used to store a SQL select statement as a string. This means that the whole select statement has to be enclosed within two ' characters. The problem is that the SQL statement itself contains these characters. The specific SQL statement i wish to save as a string is:

select
'<A HREF=DisplayOnlyDiscipline?SESSION_ID=' + :SESSION_ID +
'&DISP_REF=' + cast(DISP_REF as varchar) +
'&EDIT_REF=' + :EDIT_REF + '>' + cast(DISP_REF as varchar) + '</A>' as Reference,
V.DESCRIPTION as Discipline_Stage,
DISP_DATE as Date
from
DISCPLIN D
left outer join
V_DISP V on (V.CODE = D.DISP_CODE)
where
EMPLOY_REF = :EDIT_REF
order by
DISP_DATE DESC


Can anyone suggest how i get round this?

thanks for reading peeps

View 7 Replies View Related

Using BETWEEN With Only One Character

Nov 17, 2006

Pls, what d this query return if applied on char type (string type)
select * from myTable where myNameColumn Between 'B' AND 'E'

would return all the names that start with : B, C, D, E
like these:


Bob, Chris, Edward, David

but not :

Marry, Jean....
or how does it work exactly when applied on string type but only putting one character in the search.
Thanks.

View 1 Replies View Related

Character 0

Feb 18, 2007

How can i add character 0 to the database??

i have a string of characters and one of them is 0 (its a license file)

i would like to save it to the database. but i get unclosed character string.

Hope its clear.

Tks

its a new database so you can also tellme wich datatype i need.

View 3 Replies View Related

Tab Character

Jul 23, 2005

what nchar() value equals the tab character. I need to replace it in astring.

View 3 Replies View Related

What Is This Character/why Am I Seeing It?

Feb 29, 2008

I'm using MS SQL intelligence studio's SSIS import wizard to import some Excel files into SQL tables and for certain fields I'm getting this strange character instead of NULL. Does anyone know what this character is, how to avoid it, or a SQL query that will get rid of it? I can't even copy it to my clipboard.

View 12 Replies View Related

Get Certain Character

Mar 5, 2008



Hi
I have got a column having data like
RT 12.5R20 (P) OL
RT 12.5R244(SP)GRADER


I want only need the value before '('. So, the result will be RT 12.5R20 and RT 12.5R244
Since the length of the character will change. Is there any funtions in T-SQL that I can use to achieve this?
Thanks

View 5 Replies View Related

Replace, The ' Character, And Yea...

Aug 22, 2007

I have the following:----------------- WHILE PATINDEX('%,%',@Columns)<> 0 BEGINSELECT @Separator_position = PATINDEX('%,%',@Columns)SELECT @array_Value = LEFT(@Columns, @separator_position - 1)SET @FieldTypeID = (SELECT FieldTypeID FROM [Form].[Fields] WHERE FieldID = (CAST(@array_Value AS INT)))SET @FieldName = (SELECT [Name] FROM [Form].[Fields] WHERE FieldID = @array_Value)print 'arry value' + CONVERT(VarChar(500), @array_value)print 'FieldTypeID: ' + CONVERT(VARCHAR(500), @FieldTypeID)PRINT 'FieldName: ' + @FieldNameBEGINIF @FieldTypeID = 1 OR @FieldTypeID = 2 OR @FieldTypeID = 3 OR @FieldTypeID = 9 OR @FieldTypeID = 10 OR @FieldTypeID = 7BEGINSET @InnerItemSelect = ' (SELECT ISNULL(CONVERT(VARCHAR(MAX),[Value]),'''') FROM [Item].[ItemDetailFieldRecords] IDFR WHERE IDFR.ItemDetailID = ID.ItemDetailID AND IDFR.FieldID = ' + @array_Value + ') AS ''' + @FieldName + ''' 'SET @InnerTaskSelect = ' (SELECT ISNULL(CONVERT(VARCHAR(MAX),[Value]),'''') FROM [Item].[TaskFieldRecords] TFR WHERE TFR.TaskID = T.TaskID AND TFR.FieldID = ' + @array_Value + ') AS ''' + @FieldName + ''' 'ENDELSE IF @FieldTypeID = 4 OR @FieldTypeID = 8 --DropDownList/RadioButtonlistBEGINSET @InnerItemSelect = ' (SELECT [Value] FROM [Form].[FieldListValues] FFLV INNER JOIN [Item].[ItemDetailFieldListRecords] IDFLR ON FFLV.FieldListValueID = IDFLR.FieldListValueID WHERE IDFLR.ItemDetailID = ID.ItemDetailID AND FFLV.FIeldID = ' + @array_value + ') AS ''' + @FieldName + ''' 'SET @InnerTaskSelect = ' (SELECT [Value] FROM [Form].[FieldListValues] FFLV INNER JOIN [Item].[TaskFieldListRecords] TFLR ON FFLV.FieldListValueID = TFLR.FieldListValueID WHERE TFLR.TaskID = T.TaskID AND FFLV.FIeldID = ' + @array_value + ') AS ''' + @FieldName + ''' 'ENDELSE IF @FieldTypeiD = 5 --CascadingBEGINSET @InnerItemSelect = ' (SELECT [FCV].[Value] FROM [Form].[FieldCascadingValues] FCV INNER JOIN [Form].[FieldCascadingLookUpTables] LT ON FCV.FIeldCascadingLookupTableID = LT.FieldCascadingLookupTableID INNER JOIN [Item].[ItemDetailFieldCascadingRecords] IDFCR ON IDFCR.FieldCascadingValueID = FCV.FieldCascadingValueID WHERE IDFCR.ItemDetailID = ID.ItemDetailID AND LT.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' 'SET @InnerTaskSelect = ' (SELECT [FCV].[Value] FROM [Form].[FieldCascadingValues] FCV INNER JOIN [Form].[FieldCascadingLookUpTables] LT ON FCV.FIeldCascadingLookupTableID = LT.FieldCascadingLookupTableID INNER JOIN [Item].[TaskFieldCascadingRecords] TFCR ON TFCR.FieldCascadingValueID = FCV.FieldCascadingValueID WHERE TFCR.TaskID = T.TaskID AND LT.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' 'ENDELSE IF @FieldTypeiD = 6 --ListBoxBEGINSET @InnerItemSelect = ' (SELECT i.[CSV] FROM @ItemDetailLV i WHERE i.ID = ID.ItemDetailID AND i.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' 'SET @InnerTaskSelect = ' (SELECT it.[CSV] FROM @TaskLV it WHERE it.ID = T.TaskID AND it.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' 'ENDELSE IF @FieldTypeID = 11 --UsersBEGINSET @InnerItemSelect = ' (SELECT SU.[UserID] FROM [Security].[Users] SU INNER JOIN [Item].[ItemDetailUserRecords] IDUR ON SU.UserID = IDUR.UserID WHERE IDUR.ItemDetailID = ID.ItemDetailID AND IDUR.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' 'SET @InnerTaskSelect = ' (SELECT SU.[UserID] FROM [Security].[Users] SU INNER JOIN [Item].[TaskUserRecords] TUR ON SU.UserID = TUR.UserID WHERE TUR.TaskID = T.TaskID AND TUR.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' 'ENDELSE IF @FIelDTypeID = 12 --GroupBEGINSET @InnerItemSelect = ' (SELECT SG.[GroupID] FROM [Security].[Groups] SG INNER JOIN [Item].[ItemDetailGroupRecords] IDGR ON SG.GroupID = IDGR.GroupID WHERE IDGR.ItemDetailID = ID.ItemDetailID AND IDGR.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' 'SET @InnerTaskSelect = ' (SELECT SG.[GroupID] FROM [Security].[Groups] SG INNER JOIN [Item].[TaskGroupRecords] TGR ON SG.GroupID = TGR.GroupID WHERE TGR.TaskID = T.TaskID AND TGR.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' 'ENDENDPRINT 'Inner Item Select:' + @InnerItemSelectPRINT 'Inner Task Select:' + @InnerTaskSelectSET @IDSelect = @IDSelect + @InnerItemSelect + ', 'SET @TSelect = @TSelect + @InnerTaskSelect + ', 'SELECT @Columns = STUFF(@Columns, 1, @separator_position, '')END   --------------- That is only part of a large query that writs a SQL Query to a column in a Database. That Query (in the column) is just ran normally so I don't need to compile it each time I want to run it.THe problem I have is  @FieldName might be:     ryan's field. That apostrophe is killing me because the SQL keeps it as ryan's field, not ryan''s field(note the 2 apostrophes).  I cannot do: REPLACE(@FieldName, ''', '''') because it's not closing the apostrophes. Is there an escape character that I can use to say only one: ' ?Would the only solution be to put: ryan''s field into the Database, and just format it properly on the output?  Thanks. 

View 4 Replies View Related

Max Character In Field

Aug 1, 2004

In a SQL Server Db, what is the maximum amount of data a field can hold?

I am using right now nvarchar with a length of 4000.

Is there another setting to allow even more in a field?

Thanks all,

Zath

View 1 Replies View Related

Character Translation

Nov 14, 2001

I have a SQL Server 2000 database which uses a Cyrillic collation. The database itself is in English, but some of the tables contain text which use the Cyrillic character set. When creating an ODBC connection to the database, ODBC forces me to have the "Translate character data" option set, which means that a query or stored procedure parameter containing Cyrillic characters have the Cyrillic characters translated to plain ascii. Data returned from a query or SP with Cyrillic characters work fine.

So the question is: how can I send Cyrillic (unicode) strings to an English SQL Server, without it translating the characters between Workstation and Server? Ideas appreciated.

Thanks,
ChrisH

View 1 Replies View Related

Checking Character Set

May 2, 2002

I've forgotten the character set that I've chosen when I was installing the SQL Server 7. Is there a way to check?

I'm currently using US English version of Windows NT4 and SQL7. But interestingly, all the data is in Japanes characters. It's actually for a Japanese website, and the front-end application is written in ASP. I remember reading somewhere that it is impossible to do certain type of sorting (by some particular order for the Japanese language) as it is limited by the choice of the language of the NT OS.

The type of sorting that I'm looking at is the grouping of 5-characters. One example is in http://www.forest.impress.co.jp/aiueo.html

Would this be possible with my current setup? Or would it help if I migrate over to Windows 2000? (I'd rather not move to Japanese NT4)

Your feedback and advice would be very much appreciated!

View 1 Replies View Related

&#39;enter&#39; Character.

Aug 8, 2002

How do I replcae an 'enter' character with a space in a field? This extra spaces entered in the web form while populating the field is causing extra spaces in the field. What is the ASCII value for the 'enter' character? so that we can replace that with a space?
Thanks.
sa.

View 2 Replies View Related

Character Or Numeric As PK

Mar 14, 2001

Hello,
I am from the school of thought that you should in every case have your primary keys as numeric values only. However, where I currently work there is a project leader who is a recent FoxPro convert (I know, they are tough ones to crack). I made the suggestion recently that the keys in the table should be numeric and with him being the project leader and me just a lowely developer he said get lost. I made the point that later joining your tables together in a PK/FK relationship where the keys where character would be slower then with numeric keys. He didn't listen and now we are approaching production with a database that is really just a bunch of text file. He said that with SQL 7 it doesn't matter if the pk is numeric or character. I disagree. But I need solid documentation to take to him and to the managers to convince them. If anyone out there could advise me on this. And if anyone could give me or tell me where I could find documentation on why even in SQL 7 there is a need to use numeric keys that would be a great help and you would be making one more shop in this world a little bit more technically sound :-) Thank you in advance for your help.

kc

View 1 Replies View Related

Character Set Change

Nov 22, 2000

Can you easily change the character set during a 6.5 to 7.0 upgrade using the SQL upgrade wizard? Or do you have to rebuild master etc?

Thanks
JD

View 1 Replies View Related

How Can I Change The Character Set ?

Oct 28, 1999

I tried changing the character set of my database..transfering it btw two servers, first one with codepage850 and the second one with iso. As I expected the characters where not automatically transformed and I got some accents that are wrong.
Could anyone telle me how to transform this...do I need a filter or something ?

I'm using SQL 7.0...
Thanks for your help,

--Eric

View 3 Replies View Related

Character Length In SQL

Dec 29, 1999

What is the syntax to count the # of characters in any given field in Transact SQL?

View 1 Replies View Related

Insert A Character

Aug 30, 2001

1)How do insert a Qoute after the the last digit on this number '2208ZX12 so it looks like '2208ZX12' in sql 2000.Please show me an easier and faster way cause l have 14000 records.

View 1 Replies View Related

Insert A Character

Aug 30, 2001

Q
1)How do insert a Qoute after the the last digit on this number '2208ZX12 so it looks like '2208ZX12' in sql 2000.Please show me an easier and faster way cause l have 14000 records.

Ans:- update SomeTable
set SomeField = rtrim(SomeField) + char(39)
where right(rtrim(SomeField),1) <> ''''

Thanks Bill for the solution it works.What l need now is an explanation so l can understand what l just did. Am l right in saying that the reason the char is 39 is to ensure that all fields regardless of length will have the qoute inserted at the end? What if the insert was to be at the beggining how would the query look like?

explain this portion (where right(rtrim(SomeField),1) <> '''') why those two qoutes?Thx a mil

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved