Hi, i'm very new to programming with SQL. I'm good with query but now I have to transfer a function from my vb application to SQL something
In clear, I have a Select of two fields on multiple rows. What I want is to create in SQL what in VB I use to put one after each other every two fields of each row.
For instance:
gives:
Data Suffix
Green '-'
Red '-'
What I want my SQL to gives me is 'Green - Red -'
One problem I have is that I don't know how many lines my SELECT will return to me. For now I have made that code:
But it's not working it returns me NULL.
When I test and write set @Title= @Userfield + @Suffix, It's ok, but It gives me only the last line (because it's what it supposes to do).
Anyway any help would be great.
Thanks
Mel
In clear, I have a Select of two fields on multiple rows. What I want is to create in SQL what in VB I use to put one after each other every two fields of each row.
For instance:
Code:
Select Data,Suffix FROM t1
gives:
Data Suffix
Green '-'
Red '-'
What I want my SQL to gives me is 'Green - Red -'
One problem I have is that I don't know how many lines my SELECT will return to me. For now I have made that code:
Code:
DECLARE @Userfield as varchar(100)
DECLARE @Suffix as varchar(100)
DECLARE @Title as Varchar(300)
DECLARE cuUF CURSOR FOR
Select Userfield,Suffix FROM t1
OPEN cuUF
FETCH NEXT FROM cuUF INTO @Userfield, @Suffix
WHILE @@FETCH_STATUS = 0
BEGIN
set @Title= @Title + @Userfield + @Suffix
FETCH NEXT FROM cuUF INTO @Userfield , @Suffix
END
Select @title
CLOSE cuUF
DEALLOCATE cuUF
But it's not working it returns me NULL.
When I test and write set @Title= @Userfield + @Suffix, It's ok, but It gives me only the last line (because it's what it supposes to do).
Anyway any help would be great.
Thanks
Mel