Concatenation Of Numeric Text
May 12, 2008How do I concatenate two numeric text values to return a string?
For examples Concatenate '03' and '2008' to '032008'?
Both values are char data type
thanks!
How do I concatenate two numeric text values to return a string?
For examples Concatenate '03' and '2008' to '032008'?
Both values are char data type
thanks!
Hi,
Does anybody know how to get the next row using two numeic keys like this:
select * from cfg_trkgrp_t where (convert(varchar,column1 )+(convert(varchar,column2)) > (convert(varchar,0) + convert(varchar,1000 )))
note: colum1 and column2 are both numeric type, column 1 has value 0, column2
has value 1000
Seems like it does not work for me for different digits of values.
Thanks.
I have a table:
batch_date numeric (8,0)
batch_nmbr numeric (5,0)
batch_ctr numeric (4,0)
col4...
col5...
col6...
I am trying to select data using something like:
select col1, col2
FROM
tablename
WHERE
(BATCH_DATE +
BATCH_NMBR +
BATCH_CTR) >= (:BATCH-DATE
+ :BATCH-NMBR
+ :BATCH-CTR)
this is a mssql cursor embedded in a microfocus cobol program.
I do not get predictable results.
I have an instance where I need to concatenate some data that is stored in a text datatype. I can't cast it to a varchar/char because that may well truncate the data. I just read about UPDATETEXT, which I think I can use, but I need to use it for a bunch or rows and it looks like this works on one row at a time. Anyone have experience with this?
View 7 Replies View Relatedi want to concatenate 2 columns of type text
what am trying to do is adding an instead of trigger on update which concatenates the old value in the text column with the new value
so the problem is how i can concatenate both values since i cant declare a variable of type text.
A solution may be dividing the text column into many varchar(8000) variables and then add them but i dont know how it can be implemented or if there's an easier solution
the code am trying:
CREATE TRIGGER InsteadTrigger on tbl
INSTEAD OF Update
AS
BEGIN
if exists(select null from deleted)
begin
--am considering updating only 1 row
update tbl set theValue=((select theValue from deleted)+(select theValue from inserted))
end
i tried the writetext and updatetext functions and the problem is always related to both columns concatenation
Any solution?
thx
samham
I am a TSQL Newbie trying to concatenate two columns (DocumentNo & SequenceNo) that were created with a €œsmallint€? data type constraint in a full-text search database. I want to end up with a column containing varchar data such as €œ5-2€? where this row of data contains information about the 2nd document in a series for a person or group designated as 5.
If I could change the data type for the columns to varchar I think I could query them like this:
SELECT ("DocumentNo" + '-' + "SequenceNo") AS DocumentNoFull
FROM Full_Documents
ORDER BY DocumentNo, SequenceNo
When I try to concatenate with this query the result is a mathematical addition of the numbers, not what I am trying to achieve (which is to combine the two numbers to produce a text string).
Due to the full-text search parameters for the database I have not been able to modify the data type constraints on the two relevant columns. Is there a way to concatenate the two €œsmallint€? columns and create a new column with text data (e.g., 5-2) for each row in the table?
My research suggests that €œcasting€? could be used to convert between data types, but I have not been able to figure out how to apply it to my situation. Any help would be appreciated.
I have a database table with 2 numeric fields. The values to be inserted into these fields come from text boxes in an ASP.NET page. So in the parameters to add into these fields I simply use 'textbox1.text' & textbox2.text'.
One of the fields accepts the data within the text box and adds it into the appropriate numeric data field in the table. However on the other text box I get an error message 'Error converting data type nvarchar to numeric.'
Does anyone know why this occurs just on the one entry and not the other?, and if anyone has any suggestions on how to get around this please let me know.
Many Thanks
how to write a query to know that a column contains text or numeric data using a select sql statement.
is there any function for this???
Please help
I have a list of movies that show throughout the year. I would like to assign a unique numeric identifier to each text field.
I have provided some sample data with the output I would like. The Movie_ID in the sample data is just made up, feel free to assign any numeric identifier, preferably of the same length but not a necessity.
create table dbo.Movie_Pre_Fix
(
Report_Monthint,
IDint,
Movie_NameVarchar(50)
);
insert into dbo.Movie_Pre_Fix (Report_Month, ID,Movie_Name)
VALUES
(201406,0721312144,'SAW'),
[code]....
I have a column that I'm trying to call into a calculated measure to determine an expected contract amount (Terms in Month). The problem is that some of the terms are defined as text strings (MTM, Coterminous, One-time) while others are numbers (12, 36, etc). The entire column is recognized as text. I have a numeric value that management has agreed would be an acceptable substitution (MTM=1, Coterminous=6) and so on. I can't however, figure out how to convert those texts to a number since they are different data types. I've tried a nested IF statement, as well as a LOOKUPVALUE..I'm doing this in Power Pivot, so am limited to DAX formulas
View 4 Replies View RelatedHi,
I have found a problem with my SSIS package. The package takes a Excel File using the Excel Source/Excel connection manager objects. There's a Data Conversion Object which sets all the fields to be DT_STR and then I import the data into a Holding table using a OLEDB Destination Object.
My Excel file contains a list of Code/Description pairs. The problem I have is that I can have data such as the following
CODE
A101
A102
A103
12
1.2i
What seems to be happening is that when the data is imported into the holding table and the first rows are Alphanumeric then the fields where there's a code such as 12 get converted to NULL for some reason. If all the codes are the same type (either Alphanumeric or numericit doesn't matter, as long as they are all the same) the import works perfectly well.
I need to be able to import all of these codes without SSIS converting some to NULL. Has anyone come across this problem before? If so, is there something I am doing wrong or a workaround?
Many thanks in advance
Rob
How do I display numeric data as text string?? I need the report to spell out the number. 1 would read as One, 2 as Two ect. For example writing the amount on a check. Need to do in SSRS.
View 6 Replies View RelatedHi,
I am getting an error when I try to insert a number typed in a text box control into a Sql database table column’s type numeric(6,2). For example: If I type 35,22 into the text box, or 35, and then I submit the form to insert the data into database, I get the follow error:
System.FormatException: Input string was not in a correct format.
Line 428: CmdInsert.Parameters.Add(New SqlParameter("@Measure", SqlDbType.decimal, "Measure"))
A piece of the SP inside Sql server:
USE market26
GO
ALTER PROC new_offer
@Offer_id bigint, @Measure numeric(6,2) = null, …
What is wrong? Why it doesn’ t accept the number typed in my text box?
Thank you,
Cesar
when I run below query I got Error of Arithmetic overflow error converting numeric to data type numeric
declare @a numeric(16,4)
set @a=99362600999900.0000
The 99362600999900 value before numeric is 14 and variable that i declared is of 16 length. Then why this error is coming ? When I set Length 18 then error removed.
Guys
I'm getting the above when trying to populate a variable. The values in question are :
@N = 21
@SumXY = -1303765191530058.2251000000
@SumXSumY = -5338556963168643.7875000000
When I run, SELECT (@N * @SumXY) - (@SumXSumY * @SumXSumY) in QA I get the result OK which is -28500190448996439680147097583285.072256 ie 32 places to left of decimal and 6 to the right
When I try the following ie to populate a variable with that value I get the error -
SELECT R2Top = (@N * @SumXY) - (@SumXSumY * @SumXSumY)@R2Top is NUMERIC (38, 10)
Any ideas ??
Hi,
I have one column in which i have Alpha-numeric data like
COLUMN X
-----------------------
+91 (876) 098 6789
1-567-987-7655
.
.
.
.
so on.
I want to remove Non-numeric characters from above (space,'(',')',+,........)
i want to write something generic (suppose some function to which i pass the column)
thanks in advance,
Mandip
I need to replace Access Val() functions with similiar function in sql.
i.e. Return 123 from the statement: SELECT functionname(123mls)
Return 4.56 from the satement: SELECT functionname(4.56tonnes)
Any one with ideas please
Thanks
George
Hi,
I was trying to find numeric characters in a field of nvarchar. I looked this up in HELP.
Wildcard
Meaning
%
Any string of zero or more characters.
_
Any single character.
[ ]
Any single character within the specified range (for example, [a-f]) or set (for example, [abcdef]).
Any single character not within the specified range (for example, [^a - f]) or set (for example, [^abcdef]).
Nowhere in the examples below it in Help was it explicitly detailed that a user could do this.
In MS Access the # can be substituted for any numeric character such that I could do a WHERE clause:
WHERE
Gift_Date NOT LIKE "####*"
After looking at the above for the [ ] wildcard, it became clear that I could subsitute [0-9] for #:
WHERE
Gift_Date NOT LIKE '[0-9][0-9][0-9][0-9]%'
using single quotes and the % wildcard instead of Access' double quotes and * wildcard.
Just putting this out there for anybody else that is new to SQL, like me.
Regards,
Patrick Briggs,
Pasadena, CA
Hi,I would like to convert a dollar amount ($1,500) to represent Fifteenhundred dollars and 00/100 cents only for SQL reporting purposes. Isthis possible and can I incorporate the statement into an existingleft outer join query.Thanks in advance,Gavin
View 1 Replies View RelatedI need to concatenate two date fields so they appear in a drop-down list like this: 8:00 AM - 10:00 AM
I'm using MS SQL 2005 and my query looks like this: SELECT ClinicTimesID, ClinicID, (CTStartTime + ' - ' + CTEndTime) AS TimeSlot FROM Clinics_Times WHERE (ClinicID = 1) and I get this error: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Can I strip out the date so that only the time appears or is it even possible to concatenate these fields? If so, how?
Thanks!
Hello all, I'm trying to combine two columns of data into a third column using a formula on the thrid column. Each of the columns could contain nulls and each of the columns could contain padding after or before the data. I'm trying to use the following formula yet SQL is throwing an error. Can someone provide another set of eyes to check this out? ISNULL(LTRIM(RTRIM([user_Define_4a])),’’) + ISNULL(LTRIM(RTRIM([user_Define_1])),’’) Thanks
View 2 Replies View RelatedI am importing via DTS a .csv file. I have 2 issues:
-One field from the source needs to be inserted into two existing fields.
-Two fields from the source, First_Name and Last_Name need to be
concatenated to a destination field, Full_Name.
I do not know VB but I do know SQL.
Can anyone help?
Hi. I want to make a query that concatenate the address of the person with a comma inbetween and neglecting the null value.
table - pspersonaldata
dcno name streetbldg1 streetbldg2 streetbldg3
1 jon santol1 null santol3
2 mike mangga1 mangga2 null
3 jay langka1 langka2 langka3
4 joy null buko2 buko3
5 jean null null null
expected output is:
name address
jon santol1, santol3
mike mangga1, mangga2
jay langka1, langka2, langka3
joy buko2, buko3
jean null
thanks.
-Ron-
I am completely new to SQL and I have some syntax questions. I am trying to concatenate 4 fields and some padded constants to form a new key field to perform joins. The result should be a twelve character field without spaces. My problem is that the current fields use spaces as place holders and I need to replace the spaces with ‘0’.
[RD_ID] nvarchar length 5
[RDWY_ID] nvarchar length 1
[MLGE_TYPE] nvarchar length 1
[OVLAP_MLGE_CD] nvarchar length 1
Concatenate 12 characters
1st ‘0’ (constant)
2nd, 3rd, and 4th, from [RD_ID] (without the suffix)
5th and 6th from [RD_ID] suffix or replace spaces with ‘00’
7th 1 or 2 from [RDWY_ID]
8th Z from [MLGE_TYPE] or replace space with ‘0’
9th 1 – 9 from [OVLAP_MLGE_CD] or replace space with ‘0’
10th ‘S’ (constant)
11th ‘0’ (constant)
12th ‘0’ (constant)
Results should resemble
0001CQ100S00 or 000100100S00
This is the query I used in Access.
LRS: "0" & IIf((Len(LTrim(RTrim([HITIS2_TVCLEAR2]![RD_ID])))=3),LTrim(RTrim([HITIS2_TVCLEAR2]![RD_ID])) & "00",LTrim(RTrim([HITIS2_TVCLEAR2]![RD_ID]))) & [HITIS2_TVCLEAR2]![DIR_RDWY_ID] & IIf([HITIS2_TVCLEAR2]![MLGE_TYPE]=" ",0,[HITIS2_TVCLEAR2]![MLGE_TYPE]) & IIf([HITIS2_TVCLEAR2]![OVLAP_MLGE_CD]=" ",0,[HITIS2_TVCLEAR2]![OVLAP_MLGE_CD]) & "S00"
Thanks for any help.
My file is in this format
Col1 Col2 Col3
---------------------------------------------------------------------------
Andrews S 93845877712 P
Sylvia 9999876669 J
Bill K 7657654677 L
I need the output like this
Col1 Col2 Col3
--------------------------------------------------------------------------
AndrewsS 93845877712 P
Sylvia 99999876669 J
BillK 76576546677 L
The character on the left of Col2 has to be joined to Col1 and character on the right of col2 has to be joined to Col3. Can anybody suggest a query for this.
Thanks,
I need to concatenate the strings of the grouped result set in my report. Lets say if I have
ID Text
-----------------
1 text1
1 text2
1 text3
and if I am grouping by ID, the resulted text should be "text, text2, text3". Any ideas on this? Its kind of emergency
Thanks
Dinesh
Hi All,
I've been trying to create a dynamic query using the 'Like' clause and '%'.
my code snippet looks like this:
while (@@FETCH_STATUS = 0)begin set @likeString = @likeString + ' item_Text LIKE ''%'+@word+'%'' OR ' fetch next from theLike into @word end
-- strip off last ORset @likeString = ltrim(rtrim(substring(@likeString, 0, (len(@likeString) - 3))))-- ================================================-- create query to find keywords in the index and store in temp table-- ================================================set @query = 'INSERT into #resulttable (itemcount, item_id) SELECT COUNT(d.item_id), d.item_id FROM tp_index_details AS d INNER JOIN tp_index ON d.idx_id = tp_index.idx_id 'set @query = @query +' WHERE (d.idx_id IN (SELECT idx_id FROM tp_index AS i WHERE ( 'set @query = rtrim(@query) + @likeStringset @query = @query + ' ) AND (subscription_id = 1000))) GROUP BY d.item_id ORDER BY d.item_id DESC'
The problem is the @query string gets truncated. My question is how to get the quotes around '%' variables to work in a string?
Thanks for any help!
regards
Davej
Hi all - I have posted inquiries on this rather vexing issue before, so I apologize in advance for revisting this. I am trying to create the code to add the parameters for two CheckBoxLists together. One CheckBoxList allows users to choose a group of Customers by Area Code, the other "CBL" allows users to select Customers by a type of Category that these Customers are grouped into. When a user selects Customers via one or the other CBL, I have no problems. If, however, the user wants to get all the Customers from one or more Area Codes who ALSO may or may not be members of one or more Categories; I have had trouble trying to create the proper SQL. What I have so far:Protected Sub btn_CustomerSearchCombined_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_CustomerSearchCombined.Click Dim CSC_SqlString As String = "SELECT Customers.CustomerID, Customers.CustomerName, Customers.CategoryID, Customers.EstHours, Customers.Locality, Category.Category FROM Customers INNER JOIN Category ON Customers.CategoryID = Category.CategoryID WHERE " Dim ACItem As ListItem Dim CATItem As ListItem For Each ACItem In cbl_CustomersearchAREA.Items If ACItem.Selected Then CSC_SqlString &= "Customers.AreaCodeID = '" & ACItem.Value & "' OR " End If Next CSC_SqlString &= "' AND " <-- this is the heart of my problem, I believe For Each CATItem In cbl_CustomersearchCAT.Items If CATItem.Selected Then CSC_SqlString &= "Customers.CategoryID = '" & CATItem.Value & "' OR " End If Next CSC_SqlString = Left(CSC_SqlString, Len(CSC_SqlString) - 4) CSC_SqlString &= "ORDER By Categories.Category" sql_CustomersearchGrid.SelectCommand = CSC_SqlString End SubAny help on this is much appreciated, many thanks --
View 5 Replies View RelatedHi,
I'm trying to mak emy query dynamic such that depending upon certain conditions, the conditions in the WHERE clause change. I have my SP as shown below and it doesn't seem to work correctly this way and seems like it is not even taking it as a condition. Please advise on what is going wrong here. I'm building the @Condition variable dynamically and appending it to the where clause below. Any help wud be greatly appreciated.
Thanks
CREATE PROCEDURE dbo.CabsSchedule_ViewSchedule
(
@SiteCode smallint = 0,
@YearMonth int = NULL,
@ByYearMonth bit = 1
)
AS
DECLARE @tempYearMonth int
DECLARE @Condition varchar(1000)
SET @tempYearMonth = 0
IF @YearMonth IS NULL OR @YearMonth = 0
BEGIN
EXECUTE CabsSchedule_GetYearMonth @tempYearMonth, @YearMonth OUTPUT
END
IF @ByYearMonth = 0
BEGIN
DECLARE @Year int
DECLARE @Month int
SET @Year = CAST(SUBSTRING(CAST(@YearMonth AS VARCHAR(6)),1,4) AS INT)
SET @Month = CAST(SUBSTRING(CAST(@YearMonth AS VARCHAR(6)),5,2) AS INT)
SET @Condition = ' DATEPART ([month], FullDate) = ' + CAST(@Month AS VARCHAR(2)) + ' AND DATEPART ([year], FullDate) = ' + CAST(@Year AS VARCHAR(4)) + ' AND '
END
ELSE
BEGIN
SET @Condition = ' YearMonth = ' + CAST(@YearMonth AS VARCHAR(6)) + ' AND '
END
SELECT BillPeriod =
CASE
WHEN BillPeriod = 32 THEN 'NB'
WHEN BillPeriod = 33 THEN 'Holiday'
ELSE Convert(nVarChar(7), BillPeriod)
END,
WorkDay =
CASE
WHEN WorkDay = -1 THEN ''
WHEN WorkDay = 0 THEN 'Holiday'
ELSE Convert(nVarchar(7), WorkDay)
END,
JulianDate, CalendarDay, CalDayBillRcvd, Remarks, FullDate
FROMdbo.CabsSchedule
WHERE YearMonth = @YearMonth AND SiteCode = @SiteCode
GO
I'm trying to implement a system where I want to use something like a group by with a concatenation clause.
e.g.
Table 1.
ID Field
1 null
2 null
Table 2.
ID Value
1 AAA
1 BBB
2 CCC
2 DDD
2 EEE
Using one query I would like to transform Table 1 to
ID Field
1 AAABBB
2 CCCDDDEEE
Is there any way of doing this ? At the moment I'm using two cursors to accomplish this task, but this is not really efficient.
Maurice v/d Zwaan
i am having data something like this:
number starting point ending point
1 ABC DEF
2 DEF ABC
1 PQR STU
2 STU PQR
1 ABC DEF
2 DEF PQR
3 PQR ABC
and i want it to be like this in my new table based on number column:
CONCATENATED
ABC/DEF/ABC
PQR/STU/PQR
ABC/DEF/PQR/ABC
can anyone suggest me how to write a query for this one?
Hi all,
I am trying to concatenate two columns First_Name and Last_Name to display as Name in a View. I used the following statement but the result only shows the First_Name.
Select First_Name + Last_Name as Name from Address;
How do i combine the two columns??
SQL 2000 running on Win 2000
Thanks in advance.
Hey,
Does anyone know how to do integer concatenation using sql?
Say for instance I have 2004 and 12, I need 200412 and not 2016.
Can this be done?
Thanks