Convert String To Hex And Concatenate With

Sep 4, 2014

To start, I am NOT a SQL programmer. I have to do some minimal SQL administration (DB Creation, Backups, Security) on spatial databases that are for the most part managed by a 3rd party program. My experience with T-SQL is mostly simple tasks (i.e. Select and Update statements)..However I have been requested to calculate an ID Field using the values of two other fields. Per the request, I need to convert one field to Hex and concatenate with the second field.

ex. Field 1 + Field 2(hex string) = Field 3
Field 1 = 'FF02324323'
Field 2 = 'Smith Creek'
Field 3 = 'FF02324323536D69746820437265656B'

Field 1 VarChar(10) (Code)
Field 2 VarChar(65) (Common Name)
Field 3 VarChar(max) (ResourceID)

Spent half the day searching and have tried various forms of CAST, CONVERT, fn_varbintohexstr and others but have unable to come up with the correct combination to get what I need.

View 3 Replies


ADVERTISEMENT

Concatenate String Then Convert To Datetime

Jan 23, 2008

I've been trying to do the following:





Code Snippet
if year(@SomeDateTime) <> @SomeYear

set @SomeDateTime= convert(datetime, @SomeYear+ '1231', 112)


If variable @SomeDateTime evaluates to 20080101 and @SomeYear = 2006, I wish that my variable @SomeDateTime becomes 20061231 (December 31st).

The way it's written now, it doesn't work... @SomeDateTIme evaluates to 1908-11-12.... ?!





View 6 Replies View Related

T-SQL (SS2K8) :: How To Concatenate / Convert Date And Time Into Datetime

Aug 3, 2015

We have 2 columns:

StartDate - data type Date
StartTime - data type Time

I need to combine them into a DateTime data type. For now, I convert each of them into varchar, insert space in between, and convert to DateTime, like this:

convert(datetime, convert(varchar(10), EndDate , 101) + ' ' + CONVERT(varchar(20), EndTime,24))

Is there a better, more elegant way to do this?

View 9 Replies View Related

Transact SQL :: Convert Int To Time And Concatenate It With Datetime Field?

Sep 16, 2015

I have a datetime field for e.g 2015-09-15 00:00:00.000 and an integer field for e.g.100809.

The integer field is actually a time value as in hours,minutes,seconds. For e.g. the value

100809 means
10-hours
08-minutes
09-seconds

I need to combine the datetime and the int field to get the output as below

2015-09-15 10:08:09

View 7 Replies View Related

Concatenate String

Oct 25, 2004

Please help me with this if you can.
I have one table with CustomerID and some other data.
In other table i have CustomerID(the link with the first table) and Agent
The relation of the first with the second one is ONE TO MANY.
I want something like this:
Customer,'Agent1,Agent2,Agent3'

Is it possible.
Please help :)

View 3 Replies View Related

How To Concatenate A String To A Int Value

Mar 5, 2007

I hope this is the correct place to ask this...

I would like to concatenate a String value to an Int value using an SQL statement. At the moment it reads like this:

SELECT 'website.com/shop/product.cfm?ProductID=' + Products.ProductID AS Product_URL

But unfortunately I am getting the error:
"Conversion failed when converting the varchar value 'website.com/shop/product.cfm?ProductID=' to data type int."

Any idea how to get around this at all just using an SQL query statement?

View 2 Replies View Related

Concatenate SQL String...

Feb 20, 2008

Hi all I need some help in concatenatng a string in T-SQL. Having used the Command Microsoft Access inside the 'SQL View' window and typed the following it worked perfectly.






Code Snippet

UPDATE tblValidUsers SET blocked_users = blocked_users + 'name_123@hotmail.com;' WHERE userid='Onam'

However attempting the same command in T-SQL I get the following error:

Msg 403, Level 16, State 1, Line 1Invalid operator for data type. Operator equals add, type equals text.

Reason for having this command is I want to be able to add something to the end of the field "blocked_users" without actually overwriting the fields contents.

So for instance if I had the items: "Item1, Item2, Item3" in blocked_users and I updated it with "Item4" then the value "Item4" would be added to the end thus the use of "+" is used to concatenate. Is there a way of doing this in T-SQL?

Thanks for the help, Onam

View 6 Replies View Related

Concatenate String In Query

Apr 22, 2008

Hi,

As I build a record set in an SP I need to add in a string containing a list derived from a second query. I need the results of the sub query to be presented as a single string in the first query, separated by a single space.

I have no idea how to do this in t-sql, and am doing it on the web server at the moment, but becase the dataset is quite large, I'm getting 20 - 40 second processing times which is far too long.

I have found reference to the xp_sprintf function but this is not supported by my host, so not a solution.

I'm no expert in t-sql, so I imagine there's a way somewhere, and would be grateful for any advice available.

regards,

NEIL

Neil

View 5 Replies View Related

Concatenate A String Problem

Oct 18, 2006

Hi to all:
In my package, I have in OLE DB SOURCE a statement:

DECLARE @CMonth as smalldatetime
SET @CMonth = '11/1/2006'
select day(@CMonth)+month(@CMonth)+year(@CMonth) as ID_Month

and in OLE DB DESTINATION, I have ID_Month column as a char(10).

I want to be result as concatenated string €“ 1112006, but I receive 2018 (As a result of calculation)
Can anybody help me? Thank you

View 3 Replies View Related

Turn Hex Into Char String And Concatenate

Feb 16, 2006

I've been trying to return hex data in a way that can be concatenated.
I need the actual hex info (e.g. 0x6E3C070) as displayed
since it contains info about the path to a file.
So I can turn it into D:6E3C7 to get the path to the file.
In searching around I have come across a way to do this but can't figure out how to get it to run through a column and either display or insert into a table multiple results.

-Here's the user function that converts an integer into a hex string-

CREATE FUNCTION udf_hex_string (@i int)
RETURNS varchar(30) AS
BEGIN
DECLARE @vb varbinary(8)
SET @vb = CONVERT(varbinary(8),@i)
DECLARE @hx varchar(30)
EXEC master..xp_varbintohexstr @vb, @hx OUT
RETURN @hx
END
GO


-Using this table-

create table
XPages
(PageStoreId int null,
HexString varchar (30) null,
VolumePath varchar (60) null, )


--'PageStoreId' contains the data that needs to be converted into the editable hex string
--'HexString' is where I'd like it to go so I can parse it later.

--I can run the below select and get the hex string. But am stuck on how to run a select or update that would run through the 'XPages.PagestoreId'
column and insert the hex string into the 'XPages.Hexstring' column. 'XPages.PagestoreId' could have 100's of entries that need to be converted and placed in the relevant the 'XPages.Hexstring' column.


SELECT dbo.udf_hex_string(1234)



Thanks

View 3 Replies View Related

Concatenate String And Pass To FORMSOF?

Jul 23, 2005

The following query works perfectly (returning all words on a list called"Dolch" that do not contain a form of "doing"):SELECT 'Dolch' AS[List Name], dbo.Dolch.vchWordFROM dbo.Dolch LEFT OUTER JOINdbo.CombinedLexicons ON CONTAINS(dbo.Dolch.vchWord,'FORMSOF(INFLECTIONAL, "doing")')WHERE (dbo.CombinedLexicons.vchWord IS NULL)However, what I really want to do requires me to piece two strings together,resulting in a word like "doing". Any time I try to concatinate strings toget this parameter, I get an error.For example:SELECT 'Dolch' AS[List Name], dbo.Dolch.vchWordFROM dbo.Dolch LEFT OUTER JOINdbo.CombinedLexicons ON CONTAINS(dbo.Dolch.vchWord,'FORMSOF(INFLECTIONAL, "do' + 'ing")')WHERE (dbo.CombinedLexicons.vchWord IS NULL)I have also tried using & (as in "do' & 'ing") and various forms of singleand double quotes. Does anyone know a combination that will work?FYI, in case this query looks goofy because of the unused "CombinedLexicons"table, it is because the end result should be a working form of thefollowing...Figuring out the string concatination is just a step toward this goal:SELECT 'Dolch' AS[List Name], dbo.Dolch.vchWordFROM dbo.Dolch LEFT OUTER JOINdbo.CombinedLexicons ON CONTAINS(dbo.Dolch.vchWord,'FORMSOF(INFLECTIONAL, ' + dbo.CombinedLexicons.vchWord + ')')WHERE (dbo.CombinedLexicons.vchWord IS NULL)Thanks!

View 2 Replies View Related

Transact SQL :: Concatenate String Using Conditions?

Sep 19, 2015

I have a SQL table like this

col1      col2      col3
1           0          0
1           0          1
1           1          1
0           1          0

I am expecting output as 

col1      col2       col3      NewCol
1           0          0             SL
1           0          1             SL,PL
1           1          1             SL,EL,PL
0           1          0             EL

condition if col>0 then SL else '',  if col2>0 EL else '', if col3>0 PL else ''

View 5 Replies View Related

Looping Through Temporary Table To Concatenate A String

Mar 27, 2007

I have a large table that looks like this.
(ID INT NOT NULL IDENTITY(1,1),PK INT , pocket VARCHAR(10))
1, 1, p12, 1, p23, 2, p34, 2, p45, 3, p56, 3, p67, 4, p78, 5, p19, 5, p210,5, p83
i would like to loop through the table and concatenate the pocket filed for all the records that has the same pk. and insert the pk and the concatenated string into another table in a timely manner.
can anyone help?
i have to use temporary tables. (not cursors-with cursors i know how to di it, but i want with temporary table)
thanks in advance

View 1 Replies View Related

Concatenate A String Within A Loop From A Temp Table

May 11, 2006

I need help.

I have a large table that looks like this.

(ID INT NOT NULL IDENTITY(1,1),PK INT , pocket VARCHAR(10))

1, 1, p1
2, 1, p2
3, 2, p3
4, 2, p4
5, 3, p5
6, 3, p6
7, 4, p7
8, 5, p1
9, 5, p2
10,5, p83

i would like to loop through the table and concatenate the pocket filed for all the records that has the same pk. and insert the pk and the concatenated string into another table in a timely manner.

can anyone help?

Emad

View 9 Replies View Related

Transact SQL :: Aggregate 2 Dates And Concatenate Into New String

May 21, 2015

Have this table

ACCOU  NAME      NAME TODATE                            ID     EDUCAT    EXPIRYDATE
011647 MILUCON Empl1 1900-01-01 00:00:00.000 9751 VCA-basis 1900-01-01 00:00:00.000
011647 MILUCON Empl1 1900-01-01 00:00:00.000 9751 VCA-basis 2016-06-24 00:00:00.000
011647 MILUCON Empl1 1900-01-01 00:00:00.000 9751 VCA-VOL  2018-02-11 00:00:00.000

Need to get it like

ACCOU  NAME      NAME TODATE                            ID     EDUCAT    EXPIRYDATEstring
011647 MILUCON Empl1 1900-01-01 00:00:00.000 9751 VCA-basis 1900-01-01 00:00:00.000 2016-06-24 00:00:00.000
011647 MILUCON Empl1 1900-01-01 00:00:00.000 9751 VCA-VOL  2018-02-11 00:00:00.000

In other words I need to Aggregate the 2 dates and concatenated into a new string col string so basically a sum with a group by but instead of a sum I need to concatenate the string. I know this should be possible using stuff and for xml path but I can't seem to get my head around it everything I try concatenates all the strings, not just the appropriate ones.

View 11 Replies View Related

How Can I Concatenate A String To A Int Variable? Need Correct Combination Of Quotes!

May 26, 2008

Hi,
I need to concatenate a string with an int variable on a stored procedure; however, i looks like i am lost in single and double quotes. Does any one know the right comination of quotes for this please? My Code is below:
 1 @Price int
2
3 DECLARE @SqlPrice varchar(50)
4
5 if (@Price is not null)
6
7 set @sqlPrice = 'AND price' + '' > '' + '' + @Price + ''
8

 

View 4 Replies View Related

SIMPLE Command To Convert String To Number? Not CAST Or CONVERT.

Aug 15, 2006

Dear Experts,Ok, I hate to ask such a seemingly dumb question, but I'vealready spent far too much time on this. More that Iwould care to admit.In Sql server, how do I simply change a character into a number??????In Oracle, it is:select to_number(20.55)from dualTO_NUMBER(20.55)----------------20.55And we are on with our lives.In sql server, using the Northwinds database:SELECTr.regionid,STR(r.regionid,7,2) as a_string,CONVERT(numeric, STR(r.regionid,7,2)) as a_number,cast ( STR(r.regionid) as int ) as cast_to_numberFROM REGION R1 1.00112 2.00223 3.00334 4.0044SELECTr.regionid,STR(r.regionid,7,2) as a_string,CONVERT(numeric, STR(r.regionid,7,2) ) as a_number,cast (STR(r.regionid,7,2) as numeric ) as cast_to_numberFROM REGION R1 1.00112 2.00223 3.00334 4.0044Str converts from number to string in one motion.Isn't there a simple function in Sql Server to convertfrom string to number?What is the secret?Thanks

View 4 Replies View Related

Convert A String To Int?

Jul 10, 2014

using sql 2008, trying to convert a string to int

Example

Table1 has a varchar which i want to cast to int
00125000000 to int 125000000
i used the following
cast(B.[Assessment] as int) as [USER1_01],

with the result 125000000

Table2 has the same field in a different format.

0.00125

i need to find a way to convert one of them so they both match. if i did a join and matched the fields.

I tried

cast (10000000000 * cast([USER1_01] as NUMERIC(6,6)) as INT) as [USER1_01]

but for some reason it dosent look like they match, although they look the same. maybe a type problem?

View 3 Replies View Related

How To Convert A Number To String In SQL?

Jul 7, 2006

I search the help for T-sql, still don't know how to convert a number, for example 12345 to a string with formating like 12,345
Thanks for your help.

View 1 Replies View Related

Object Convert To String....

Jul 17, 2007

Hello all,Currently i am having problem with the conversion from object to string. I am using SqlCommand to draw data from DB, and the statement i used is:String ires = myCommand.ExecuteScalar().ToString();and then convert ires to int by int.Parse(ires) I have got no problem during the compilation, but it gives me the exception during the runtime...any one got any ideas? Thanks 

View 11 Replies View Related

Convert SqlDataSource To String.

Aug 1, 2007

I'm working with an SqlDataSource, and I'm just wondering how to get the data to a String if I'm sure the select statement will only return 1 piece of data. Any ideas?

View 2 Replies View Related

How To Convert Null To A String

May 12, 2004

I want all the null (blank) values returned by a stored procedure to be shown as a string like "n/a", how to do that easily? Thanks

View 2 Replies View Related

How To Convert String To DateTime

Jan 2, 2006

hi , i have a problem
i have an textarea that i want to convert to DateTime format (dd/MM/yyyy) .
the data in the textarea is (dd/MM/yyyy for example 21/12/2005).
i need it to add this data in sql server , in smalldatetime formation colum .
plz help.
 
 

View 2 Replies View Related

How To Convert A Hex String To An Integer?

Feb 1, 2000

Hi folks,
I'm trying to import data from a text file (UnicodeData.txt) into
an SQL table. Some of the fields are unicode values (16 bits)
expressed as four hexidecimal digits. I've succeeded in importing
the data as character strings, but I have not found a way to convert
them into numbers. (They could be stored as int or nchar.)
I've tried convert(binary/int/whatever, string); E.g.
select convert(int, '0x1111') from import_unicode
gives the error
Syntax error converting the varchar value '0x1111' to a column of data type int.

I could write code to strip off one character at a time, convert the
hex digit to a decimal value, shift left, etc., but I find it hard
to believe that's the best way.

Any help is appreciated. Please email answer to lars_huttar@sil.org
as I don't read this board.

Thanks,
Lars Huttar
lars_huttar@sil.org

View 3 Replies View Related

Convert String To Date In DTS

Dec 7, 1999

I'm using SQL 7.0 SP1.

I am using DTS to read in a date with the format of YYYYMMDD. I am trying to convert this date to MM/DD/YYYY and then use the CDate function with the following code to load it into a Datetime column in SQL Server:

Function Main()
strDate = DTSSource("Col002")
strYear = Left(strDate, 4)
strMonth = Mid(strDate, 5, 2)
strDay = Right(strDate, 2)

strHoldDate = strMonth + "/" + strDay + "/" + strYear

DTSDestination("DateName") = strHoldDate
Main = DTSTransformStat_OK
End Function

My DTS package will execute without errors, but it does not add the row. I have been successful using CDate when the source date is in the format MM/DD/YYYY.

Also, do you have any tips on how to debug DTS? How to see what's in a variable, etc.?

Thanks!
Lisa

View 1 Replies View Related

Convert To Date From String

Oct 29, 2014

In our ERP system we have a field which is a date-picker in the user front end, but the value is stored in an NVARCHAR field and not always consistently. How can I convert this to a date (preferably in the format YYYY-MM-DD HH:MM) that I could use in a calculation?

select code, spec_value from spec_checklist_remind where spec_checklist_id = 17

code spec_value
------------ -----------------------------------------------------------------------
05MC0001 22/07/2014
05MC0002 23/07/2014
06MT0001 01-May-2014
06MT0002 01-May-2014
06MT0006 01/05/2014
06MT0007 01-May-2014
06MT0008 01/05/2014

View 5 Replies View Related

How To Convert String To Number

Dec 6, 2014

I have a column which keeps numeric data in form of String, but I want to convert it to number e.g. from "1001" to 1001,

Which function I can use to do it?

[URL] .....

View 2 Replies View Related

Can I Convert/reference A String To A Var?

Jul 13, 2006

hey, guys

I got a strange question. :)

In SQL Server,
declare @Item8 as varchar(100)
declare @str as varchar(100)
set @str = '@Item8'
Is there any way I can reference @str to @Item8 ?

Thanks

View 1 Replies View Related

How To Convert A Bit String To 0x Number?

Jul 19, 2006

hi,

I have a bit string like '000111010101101110000111' , how to convert it to varbinary format like 0x1D5B83?

Thanks.

View 1 Replies View Related

Convert String To Smalldatetime

May 4, 2007

Hi,



I am new to SSIS and have been trying to load a date from a Table1.ColumnA (varchar(50)) to a Table2.ColumnB(smalldatetime).



I tried using the Derived Column and Data Conversion controls but I get the below error.

Error converting data type DBTYPE_DBTIMESTAMP to datetime



What do I do to load this data.



Thanks,

Noel

View 8 Replies View Related

Convert String To Numeric

Jul 29, 2007



Hi all,
I defined an user string type varible in the package as AccountLen. I am trying to use this varible in the Expression of Derived Column transformation.
I want to retrieve a part of column, i.e: Right(Column1, @AccountLen), this is always wrong because the AccountLen is string type. How I can convert it to the numeric so that can be used in the RIGHT function?
Thanks

View 3 Replies View Related

Convert From Binary To String

Jan 15, 2008

Hi Everyone -
iam facing a small problem i want to convert an output from the context_info() which is binary to string (or int)

example:

SET CONTEXT_INFO 3


select CONTEXT_INFO() --- it will return 0x0000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

the requested output is to be 3 again


thanx
Maylo

View 3 Replies View Related

Query To Convert String To Int

Oct 4, 2007



CREATE TABLE USERTABLE(
USERID int,
USERNAME varchar(20));

INSERT INTO USERTABLE VALUES (1,'x');
INSERT INTO USERTABLE VALUES (2,'y');
INSERT INTO USERTABLE VALUES (3,'z');


CREATE TABLE ACCESSTABLE(
ACCESSTYPE varchar(50),
USERIDS varchar(20));

INSERT INTO ACCESSTABLE VALUES('Enabled Users','1,2');
INSERT INTO ACCESSTABLE VALUES('Disabled Users','3');

Select USERNAME from USERTABLE where USERID IN (select USERIDS from ACCESSTABLE where ACCESSTYPE='Enabled Users');


I get the following error for the above query.

Syntax error converting the varchar value '1,2' to a column of data type int.


Please advice me.

View 1 Replies View Related







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