retrieving column's data
-
somebody please help me.... i'm using vb.net 2008 and SQL Server 2008... the case is : -------------------------------------------------- if i have data in one column like : ASD654-100-CCCEEE4444-200- what query can be used to get "CCCEEE4444" ????
-
somebody please help me.... i'm using vb.net 2008 and SQL Server 2008... the case is : -------------------------------------------------- if i have data in one column like : ASD654-100-CCCEEE4444-200- what query can be used to get "CCCEEE4444" ????
SELECT SUBSTRING('ASD654-100-CCCEEE4444-200-',12,10)
Instead of string value give column name.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
somebody please help me.... i'm using vb.net 2008 and SQL Server 2008... the case is : -------------------------------------------------- if i have data in one column like : ASD654-100-CCCEEE4444-200- what query can be used to get "CCCEEE4444" ????
Use SUBSTRING function
SELECT SUBSTRING([ColumnName],12,10) FROM [Table]
thatraja |Chennai|India|
Tips/Tricks|Brainbench certifications
Do what you want quickly because the Doomsday on 2012 :-)
-
Use SUBSTRING function
SELECT SUBSTRING([ColumnName],12,10) FROM [Table]
thatraja |Chennai|India|
Tips/Tricks|Brainbench certifications
Do what you want quickly because the Doomsday on 2012 :-)
but i'll never know the starts index and the length of string. coz the data is randomize. example : i want to get "ASD654" and "CCCEEE4444" from the data : "ASD654-100-CCCEEE4444-200-" or to get "QWEQWEQ" and "JJJLLL" and "PPPBBMMNN" from : "QWEQWEQ-2000-JJJLLL-20-PPPBBMMNN-600-" any idea? :-D
-
SELECT SUBSTRING('ASD654-100-CCCEEE4444-200-',12,10)
Instead of string value give column name.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
it will not work. coz i'll never know the starts index and the length of string. coz the data is randomize. example : i want to get "ASD654" and "CCCEEE4444" from the data : "ASD654-100-CCCEEE4444-200-" or to get "QWEQWEQ" and "JJJLLL" and "PPPBBMMNN" from : "QWEQWEQ-2000-JJJLLL-20-PPPBBMMNN-600-" any idea? :-D is there any query for looping? :-D
-
it will not work. coz i'll never know the starts index and the length of string. coz the data is randomize. example : i want to get "ASD654" and "CCCEEE4444" from the data : "ASD654-100-CCCEEE4444-200-" or to get "QWEQWEQ" and "JJJLLL" and "PPPBBMMNN" from : "QWEQWEQ-2000-JJJLLL-20-PPPBBMMNN-600-" any idea? :-D is there any query for looping? :-D
Well, you have to use
-
as split char, by writting your own function then you can get result as you need.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
Well, you have to use
-
as split char, by writting your own function then you can get result as you need.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
how to split char "-" in SQL ? is there a function for looping in SQL ? teach me please... i'm begging... pleaseee..... ;)
-
but i'll never know the starts index and the length of string. coz the data is randomize. example : i want to get "ASD654" and "CCCEEE4444" from the data : "ASD654-100-CCCEEE4444-200-" or to get "QWEQWEQ" and "JJJLLL" and "PPPBBMMNN" from : "QWEQWEQ-2000-JJJLLL-20-PPPBBMMNN-600-" any idea? :-D
For that you should write UDF, depends upon the random data you should define the things & write script for that.
thatraja |Chennai|India|
Tips/Tricks|Brainbench certifications
Do what you want quickly because the Doomsday on 2012 :-)
-
For that you should write UDF, depends upon the random data you should define the things & write script for that.
thatraja |Chennai|India|
Tips/Tricks|Brainbench certifications
Do what you want quickly because the Doomsday on 2012 :-)
i agree with blueboy where i have to use "-" as split char. but the problem is i don't know how to split char using SQL Query. and i think i need function for looping using SQL Query too. can u help me pleaseee? i'm begging.... :-D
-
i agree with blueboy where i have to use "-" as split char. but the problem is i don't know how to split char using SQL Query. and i think i need function for looping using SQL Query too. can u help me pleaseee? i'm begging.... :-D
Try this link SQL Server 2005 - Loop through/split a delimited string[^]
thatraja |Chennai|India|
Tips/Tricks|Brainbench certifications
Do what you want quickly because the Doomsday on 2012 :-)
-
Try this link SQL Server 2005 - Loop through/split a delimited string[^]
thatraja |Chennai|India|
Tips/Tricks|Brainbench certifications
Do what you want quickly because the Doomsday on 2012 :-)
wow... that code was very hard to understand.. i'm still a newbie here. but thanks alot friend. it helps and i'll try... :-D
-
wow... that code was very hard to understand.. i'm still a newbie here. but thanks alot friend. it helps and i'll try... :-D
siang_wu_id wrote:
that code was very hard to understand
May be, for big works probably we need to write massive code(at least bunch of code).
siang_wu_id wrote:
i'm still a newbie here. but thanks alot friend. it helps and i'll try...
It's really great.:thumbsup:
thatraja |Chennai|India|
Tips/Tricks|Brainbench certifications
Do what you want quickly because the Doomsday on 2012 :-)
-
somebody please help me.... i'm using vb.net 2008 and SQL Server 2008... the case is : -------------------------------------------------- if i have data in one column like : ASD654-100-CCCEEE4444-200- what query can be used to get "CCCEEE4444" ????
Hi, I suggest you create a split function
CREATE FUNCTION [dbo].[Split]
(
@delimited nvarchar(max),
@delimiter nvarchar(100))
RETURNS @t TABLE
(
id int identity(1,1),
val nvarchar(max))AS
BEGIN
declare @xml xml
set @xml = N'<root><r>' + replace(@delimited,@delimiter,'</r><r>') + '</r></root>'insert into @t(val)
select
r.value('.','varchar(15)') as item
from @xml.nodes('//root/r') as records(r)RETURN
ENDThen cross apply to return your desired column. eg.
declare @tmp table (value varchar(100))
insert into @tmp values ('ASD654-100-CCCEEE4444-200-')
insert into @tmp values ('QWEQWEQ-2000-JJJLLL-20-PPPBBMMNN-600-')select val
from @tmp
cross apply dbo.split(value,'-')
where id = 3Ryan