Transact SQL :: Need To Select And Convert To First Name / Last Name And Remove Comma
Oct 14, 2015
I have a table that holds full names but it's lastname, firstname.I need to select and convert to firstname lastname and remove the comma.
View 7 Replies
ADVERTISEMENT
Nov 25, 2015
i had a query for generating full address from add1,add2,add3 fields.
declare @temp table
(ADDR1 varchar(10),
ADDR2 varchar(10),
ADDR3 varchar(10)
[code]....
but still i am getting ',' for second record as u seen when ADD1 is null.so how can i remove that comma','
View 3 Replies
View Related
Jul 28, 2015
I have a string variable
string str1="1,2,3,4,5";
I have to use the above comma separated values into a SQL Search query whose datatype is integer. How would i do this Search query in the IN Operator of SQL Server. My query is :
declare @id varchar(50)
set @id= '3,4,6,7'
set @id=(select replace(@id,'''',''))-- in below select query Id is of Integer datatype
select *from ehsservice where id in(@id)
But this query throws following error message:
Conversion failed when converting the varchar value '3,4,6,7' to data type int.
View 4 Replies
View Related
Nov 14, 2013
I have a list of id concat them and remove the last comma at the end.
DECLARE @TempGroup TABLE
(
CounterId INT IDENTITY(1,1) NOT NULL,
HIXID VARCHAR(50) NULL
);
INSERT @TempGroup
SELECT 220100000000002
[code]....
View 2 Replies
View Related
Mar 11, 2008
Hi All,
I have one field with different values like
F1
A,B,C,
D,E
G,H,I,
My requirement is to remove the last comma from that string. I need the output should look like
F1
A,B,C
D,E
G,H,I
thanks,
Mears
View 9 Replies
View Related
May 3, 2015
I have a table Sample with data stored like below
ID|STRING |
------------------------------------------------------------------
1| 'ENGLAN SPAIN' ITALY 'FRANCE GERMANY' BRAZIL
I need the output like..
-----------------
|ENGLAND SPAIN |
|---------------|
|ITALY |
|---------------|
|FRANCE GERMANY |
|---------------|
|BRAZIL|
-----------------
How can I do the same with a select query in SQL Server?
View 4 Replies
View Related
Oct 8, 2008
I have a parameter called Id in my SP which will be of nvarchar data type and i'm going to get the multiple ids at a time seperated by commas in that parameter from the application. Now my requirement is to update a table with these comma seperated ids in seperate rows.
For example, if i have 2 parameters called Id1 and Id2. Id1 will contain only one value and will be of int data type and Id2 will be of nvarchar data type as i can get multiple ids delimited by a comma from the application.
Suppose Id1 = 1 and Id2 = '1,2,3,4'. Then I have to update id2 in the tables seperately like wherever Id1 is '1' i need to update Id2 column for 4 rows with the value 1, 2, 3, 4 respectively in different rows.
how can i do this in T-SQL? How can i split the data of parameter Id2 in 4 different rows?
View 24 Replies
View Related
Jun 4, 2015
I want to populate data from Production to UAT(except Identity column).For that I created query,its generating script what i have required.But in last column getting with comma.I should eliminate the last comma.
script to my requirement:
declare @TABLE_SCHEMA varchar(10)
set @TABLE_SCHEMA='dbo'
declare @TABLE_NAME varchar(100)
set @TABLE_NAME='Demo_Table'
SELECT ORDINAL_POSITION AS COLUMN_POSTION ,TABLE_SCHEMA,TABLE_NAME
[Code] ....
View 12 Replies
View Related
Aug 5, 2015
I have a replace statement like the following:
select (replace('FMG','FMG','FM'))
So this is straightforward as it will replace the word 'FMG' with 'FM'
However, SSRS is passing a comma separated list like this:
select (replace('FMG','AFM','FMG','FM'))
And what I need to do is replace the comma separated list of 'FMG','AFM' only. I tried this:
select (replace('''FMG','AFM''','FMG','FM'))
But it still complaining about syntax errors. How do I get the comma separated list to be seen by the replace function?
View 7 Replies
View Related
May 16, 2015
I have a table that has some comma separated values and then have another table with the lookup values. I"m not sure why it was created this way and have not had to do this. This is a vendor database so I can't go around and changing things.
Table A
IDStageIDs
188
288,86,87
388,87
Table B (Lookup table)
IDName
86test1
87test2
88test3
Expected results
StageIDsResult
88 test3
88,86,87test3, test1, test2
88,87 test3, test2
View 2 Replies
View Related
Jun 8, 2007
Hi All
I am using SQL Server 2005 with SP2. I have multi select parameter in the report. In SP2 reporting services gives Select All option in the drop down.
Is there any way I can remove that option from the list?
Thanks
View 4 Replies
View Related
Nov 2, 2015
I have a table and one of the column have tab delimited value and I need to separate the tab delimited values and keep them in separate rows.
ID Name State Country
1 Scott, Ricky NSW AUS
2 Martin VIC AUS
3 James, Peter,John WA AUS
ID column is not a primary key. I want the output columns to identify the comma (,) and put them in separate rows as below
ID Name State Country
1 Scott NSW AUS
1 Ricky NSW AUS
2 Martin VIC AUS
3 James WA AUS
3 Peter WA AUS
3 John WA AUS
How to strip the camma(,) in SQL?
View 3 Replies
View Related
Jun 12, 2015
I am try to use a variable containing comma separated values in the IN clause.
View 10 Replies
View Related
Aug 21, 2015
I have 3 variables that gets comma separated values. My requirement is to get them into a temporary table with 3 columns and each column should have single value. E.g. if
Declare @SID varchar(max),@CID VARCHAR(MAX),@KID VARCHAR(MAX)
Set @SID='1,2,3,4'
Set @CID='6,7,8,9'
Set @KID='A,BB,CCC,DDDD'
--Now my requirement is to get them in a temp table with 3 column and different rows as per comma separated values in variables.
Now my requirement is to get them in a temp table with 3 columns and different rows (as per number of comma separated values in variables) E.g.
16A
27BB
38CCC
49DDDD
How i can use them for joining with other tables.
View 5 Replies
View Related
Jul 14, 2015
The Input parameters will be supplied like below for a procedure.
DECLARE @Subject NVARCHAR(100) = 'Math, Physics, Science'
,@ClassNumber NVARCHAR(MAX) = '102,103|415,206|712,876'
/*
I need to select subject with classnumber's supplied from the input screen and output a result like this.Let's say I have a temporary table dbo.TableA
--For Math
INSERT INTO dbo.TableA
SELECT @Subject FROM Class
WHERE @ClassNumber in (102,103)
[code]....
View 6 Replies
View Related
Sep 8, 2015
I have a requirement, we need to pass comma separated list using powershell script.
How can we achieve the above scenario?
View 3 Replies
View Related
Oct 21, 2015
I have an input parameter of an SP which value will be passed with different combinations with 2 seperators (comma and pipe)
Value to the parameter is like this : '10|22|microsoft,20|25|sql,30|27|server,40|29|product'
I want output like this
Column1 Column2 Column3
10 22 microsoft
20 25 sql
30 27 server
40 29 product
Pipe separator is for column and comma separator is for row.
I know if its a single separator, it can be done with function but how to do if its 2 separators?
View 6 Replies
View Related
Jun 19, 2015
i have the following:
DECLARE @Table TABLE (
OrgRoleNumTxt VARCHAR(10)
, AccountNm varchar(100)
, EffectDate DATETIME
, OperationNm varchar(100)
, Premium decimal(18,2)
)
Insert into @Table(OrgRoleNumTxt, AccountNm, EffectDate, OperationNm, Premium) VALUES
('00236', 'R.R. Donnelley', '2010-01-01', 'Chicago', 1000),
('00236', 'R.R. Donnelley', '2010-01-01', 'Boston', 3000)
select *
from @Table
but want this
Is it possible using basic T-SQL?
View 8 Replies
View Related
Aug 4, 2015
I am simplifying things here. Basically I have:
SELECT ......... (my selection criteria)
where Id in (@Haulers);
@Haulers is supposed to be a comma delimited list. What do I need to do to make it filter correctly?
View 13 Replies
View Related
Sep 14, 2015
I have values in two columns separated by commas, like shown below:
I need the Output Like
How to do this in SQL server ?
View 6 Replies
View Related
Jan 21, 2014
I have value with data type nvarchar:
total
000000854.00
000000042.00
000000065.17
000000000024
000000000.24
How can i convert to decimal and remove 0 infront? but those with 0.xx would not remove the 0 after the dote.
total
854.00
42.00
65.17
24
0.24
View 6 Replies
View Related
May 12, 2015
I've to write a function to return a comma delimited values from a table columns
If a table has Tab1 ( Col1,Col2,Col3).
E.g. as below ( the columnName content I want to use as columns for my pivot table
CREATE FUNCTION [RPT].[GetListOfCol]
(
@vCat NVARCHAR(4000)
)
RETURNS @PList
AS
BEGIN
SELECT @PList += N', [' + [ColumnName] +']'
FROM [ETL].[TableDef]
WHERE [IsActive] = 1
AND [Category] = @vCat
RETURN;
END;
I want out put to be as below, I am getting this output from the select query independently by declaring @Plist variable and passing @vcat value, now I want it to be returned from a function when called from a select query output ,Colum1,column2,....
View 13 Replies
View Related
Jul 16, 2015
I am need to create comma separated list in sql and I am using below query.
declare @ConcatenatedString NVARCHAR(MAX)
select @ConcatenatedString = COALESCE(@ConcatenatedString + ', ', '') + CAST(rslt.Number AS NVARCHAR)
from
(
select 1 Number
union
select 2 Number
union
select 3 Number
)rslt
select @ConcatenatedString
When I use the above code inside a function, i am not getting desired output.
create function GetConcatenatedValue
AS
(
declare @ConcatenatedString NVARCHAR(MAX)
select @ConcatenatedString = COALESCE(@ConcatenatedString + ', ', '') + CAST(rslt.Number AS NVARCHAR)
from
(
select 1 Number
union
select 2 Number
union
select 3 Number
)rslt
return @ConcatenatedString
)
View 3 Replies
View Related
Jul 2, 2015
Picture tells all what i need. Anyway i want to combine upper two tables data like below result sets. Means they should be grouped by bsns_id and its description should be comma separated taken from 2nd table. In sql server 2012 ....
View 5 Replies
View Related
May 14, 2008
Not sure the best way to do this. They are passing in a comma seperated string. I have a field that has comma seperated strings in it. I need to compare the 2 strings and do a select on that field that has any of the words in the string passed in. So if the pass...
"car,boat,van"
and in the field 2 of the 3 records get sent back
car,train,bike
boat,truck,plane
bike,plane,train
I would send them back the top 2 because the top one contains car and the second contains boat
View 5 Replies
View Related
Aug 3, 2015
I'm getting data from a flat file and there is space before few values. I'm unable to remove that space through replace or LTRIM. How to remove these spaces.For E.g.
Values
' 2356'
' 1'
' 23'
' ABCD'
View 3 Replies
View Related
Jun 2, 2015
I have a table that is used to build rules. The rules point to other columns in other tables and usually contain only one value (i.e. ABC). But one of the options is to add a comma-separated list of SSNs (i.e. 123123123,012012012,112231122). I am trying to build a single query that allows me to leverage that list to get multiple rows from another table.
This obviously works:
SELECT * FROM vw_Person_Profile P (NOLOCK)
WHERE P.PrsnPIISSN_Chr IN ('123123123','012012012','112231122')
But this does not:
SELECT * FROM vw_Person_Profile P (NOLOCK)
WHERE P.PrsnPIISSN_Chr IN (
SELECT '''' + REPLACE(CONVERT(VARCHAR(4000),txtFieldValue), ',', ''',''') + ''''
FROM MassProcessing_Rules PR
WHERE PR.intRuleID = 10
)
View 5 Replies
View Related
Nov 2, 2003
Dear SQL,
Lets say I have a field: User_Names
and it can have more than one name
example: "Yovav,John,Shon"
How can I select all the records that has "Yovav" in them ?
I try some like this:
SELECT * FROM User_Table WHERE User_Names IN ('Yovav')
but it only works if the field User_Names only has "Yovav" in it with no extras...
is there some SQL function to tell if string is found in a field ?
Any hope 4 me ?
View 2 Replies
View Related
Jun 3, 2008
Hello
I have a table with column Options where each field contains a comma delimited list of ID numbers.
I want to select any records where a certain ID number appears in that list.
So something like:
SELECT * FROM Table t1
WHERE MyID IN (SELECT Options FROM Table t2 WHERE t1.ID = t2.ID)
But that gives me the error:
Syntax error converting the varchar value '39,20' to a column of data type int.
I feel I'm close though! Could anyone point me in the right direction?
Many thanks
Square
View 3 Replies
View Related
Oct 29, 2014
i have a list of data as below:
Company Email
A AAA@abc.com
A BBB@abc.com
B xxx@def.com
i would like to write a query to list out as below where select the company A
AAA@abc.com, BBB@abc.com, ...
View 2 Replies
View Related
May 29, 2008
help please
i have this table
number_row fld_index vtext
----------------------------------------
1 101 a
2 101 b
3 101 c
4 102 d
5 102 e
6 102 f
7 103 g
8 103 h
9 103 i
......
......
....
now i need to do this
SELECT fld_index
FROM table_index
GROUP BY fld_index
----------------------------
and i get
101
102
103
104
how split this select and do this
in('101' ,'102','103','104')
------------------------------
Code Snippet
DECLARE @aaa
set @aaa =(SELECT fld_index FROM table_index GROUP BY fld_index)
set fld1 = CASE WHEN fld1 in(@aaa ) then '*' else fld1 end ---- need to split the @aaa ,'101' ,'102' , '103','104' ,
----------------------------------------------------------------------------------------------------------------------------
instead of this update
update [dbo].[tb_pivot_big]
set fld1 = CASE WHEN fld1 in('101' ,'102','103','104') then '*' else fld1 end
, fld2 = CASE WHEN fld2 in('101' ,'102','103','104') then '*' else fld2 end
, fld3 = CASE WHEN fld3 in('101' ,'102','103','104') then '*' else fld3 end
, fld4 = CASE WHEN fld4 in('101' ,'102','103','104') then '*' else fld4 end
, fld5 = CASE WHEN fld5 in('101' ,'102','103','104') then '*' else fld5 end
from [dbo].[tb_pivot_big]
View 23 Replies
View Related
Sep 25, 2015
I have a table contain ProductMaster and it is using in multiple table like sales,purchase,inventory,production and many of other tables. i want delete all product which are not using in any child table.
View 8 Replies
View Related
Aug 26, 2011
i have a data base sql Server .I wrote a stored procedure or attach my database but it is attached in read only mode how can remove read-only.
this is my stored procedure.
create procedure attache
as
declare @trouvemdf int
declare @trouveldf int
if exists (select name from sysdatabases where name='Gestion_Parc')
[Code] ....
i try this EXEC sp_dboption 'Gestion_Parc', 'read only', 'FALSE' but it causes those error
Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "C: Gestion_Parc.mdf". Operating system error 5: "5 (Access is denied.)".
Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "C: Gestion_Parc_log.ldf". Operating system error 5: "5 (Access is denied.)".
Msg 945, Level 14, State 2, Line 1
[Code] ....
View 3 Replies
View Related