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.
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:
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'
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?
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?
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.
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:6E3C 7 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
--'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.
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!
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 ''
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
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.
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.
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
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
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
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?
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.
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.
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:
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.?
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
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
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