473,473 Members | 2,226 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to concatenate in sql server

375 Contributor
Hello,
Now I want to concatenate the pin numbers which I have underlined in the code.
But somehow it does not.
What's the correct way
Kindly help
Regards
cmrhema

Expand|Select|Wrap|Line Numbers
  1.  
  2. declare @CrdPinNo varchar(100)
  3. declare @CrdNo nvarchar(100)
  4. declare @count int
  5. declare @inc int
  6. declare @concat nvarchar(200)
  7. declare @Result nvarchar(50)
  8. declare @desc nvarchar(500)
  9.  
  10.  
  11. select @count=count(cardno) from vendorcardvalidation where cardvalue=1500 and flag=0
  12. print @count
  13. if (@count)>2
  14. begin
  15.  
  16.     declare cur1 cursor for
  17. select top(2) pin,cardno from vendorcardvalidation where cardvalue=1500 and flag=0 order by cardno
  18.  
  19.     open cur1
  20.  
  21.     fetch next from cur1 into @CrdPinNo,@CrdNo
  22.  
  23.     while(@@fetch_status=0)
  24.     begin
  25.  
  26.  
  27. update vendorcardvalidation set flag=1 where cardno=@CrdNo
  28. select @concat='@concat'+@CrdPinNo
  29.                             print @concat
  30.  
  31.  
  32.  
  33.     fetch next from cur1 into @CrdPinNo,@CrdNo
  34.     end
  35.     close cur1
  36.     deallocate cur1    
  37.             set @desc=@concat
  38.             set @Result='Success'
  39. print @desc
  40. end
  41. else
  42. begin
  43.     set @desc='Inadequate numbers'
  44.     set @Result='Failure'
  45. end
Nov 6 '07 #1
5 14514
ck9663
2,878 Recognized Expert Specialist
Hello,
Now I want to concatenate the pin numbers which I have underlined in the code.
But somehow it does not.
What's the correct way
Kindly help
Regards
cmrhema

Expand|Select|Wrap|Line Numbers
  1.  
  2. declare @CrdPinNo varchar(100)
  3. declare @CrdNo nvarchar(100)
  4. declare @count int
  5. declare @inc int
  6. declare @concat nvarchar(200)
  7. declare @Result nvarchar(50)
  8. declare @desc nvarchar(500)
  9.  
  10.  
  11. select @count=count(cardno) from vendorcardvalidation where cardvalue=1500 and flag=0
  12. print @count
  13. if (@count)>2
  14. begin
  15.  
  16.     declare cur1 cursor for
  17. select top(2) pin,cardno from vendorcardvalidation where cardvalue=1500 and flag=0 order by cardno
  18.  
  19.     open cur1
  20.  
  21.     fetch next from cur1 into @CrdPinNo,@CrdNo
  22.  
  23.     while(@@fetch_status=0)
  24.     begin
  25.  
  26.  
  27. update vendorcardvalidation set flag=1 where cardno=@CrdNo
  28. select @concat='@concat'+@CrdPinNo
  29.                             print @concat
  30.  
  31.  
  32.  
  33.     fetch next from cur1 into @CrdPinNo,@CrdNo
  34.     end
  35.     close cur1
  36.     deallocate cur1    
  37.             set @desc=@concat
  38.             set @Result='Success'
  39. print @desc
  40. end
  41. else
  42. begin
  43.     set @desc='Inadequate numbers'
  44.     set @Result='Failure'
  45. end

try

select @concat='@concat'+ cast(@CrdPinNo as varchar)
Nov 6 '07 #2
cmrhema
375 Contributor
try

select @concat='@concat'+ cast(@CrdPinNo as varchar)
Thanks
But this returns only the last pin not both the values
Nov 6 '07 #3
amitpatel66
2,367 Recognized Expert Top Contributor
Dont use dingle quotes because you are refering to value of the variable and not to the had coded value '@concat'

Try:

SELECT @concat = @concat + @pincode
print @concat
Nov 6 '07 #4
sayedul
12 New Member
Try this (should work):

Expand|Select|Wrap|Line Numbers
  1.  
  2. select @concat = isnull(@concat,'') + @CrdPinNo
  3.  
  4.  
Nov 6 '07 #5
cmrhema
375 Contributor
Try this (should work):

Expand|Select|Wrap|Line Numbers
  1.  
  2. select @concat = isnull(@concat,'') + @CrdPinNo
  3.  
  4.  
Thanks all three of you
Infact solved it in a different way
Now the procedure looks very different

Expand|Select|Wrap|Line Numbers
  1. ALTER procedure [dbo].[VTELcardvalidation1] 
  2. @CardValue1 int,
  3. @CardValue2 int,
  4. @CardValue3 int,
  5. @Result nvarchar(50)output
  6.  
  7. as
  8. begin
  9.  
  10. declare @CrdPinNo varchar(100)
  11. declare @CrdNo nvarchar(100)
  12. declare @count int
  13. declare @inc int
  14. declare @concat nvarchar(200)
  15.  
  16. create table #temptable(crno nvarchar(50),pno nvarchar(50))
  17.  
  18.  
  19. --First Card
  20.  
  21. --Change here
  22. select @count=count(cardno) from vendorcardvalidation where cardvalue=1500 and flag=0
  23.  
  24. if (@count)>@CardValue1
  25.     begin
  26. declare cur1 cursor for
  27. select top(@CardValue1) pin,cardno from vendorcardvalidation where cardvalue=1500 and flag=0 order by cardno
  28. open cur1
  29. fetch next from cur1 into @CrdPinNo,@CrdNo
  30. while(@@fetch_status=0)
  31. begin
  32. update vendorcardvalidation set flag=1 where cardno=@CrdNo
  33. insert into #temptable values(1500,@CrdPinNo)
  34. fetch next from cur1 into @CrdPinNo,@CrdNo
  35. end
  36. close cur1
  37. deallocate cur1    
  38. set @Result='Success'
  39. end
  40. else
  41. begin
  42. set @Result='Failure'
  43. end
  44. select * from #temptable
  45. drop table #temptable 
  46. end
I was supposed to fetch records from database and if the cardvalues(denomination of 500,1000 etc) exists update the flag to 1.
This means that the card has been sold out.
I created a temporary table, stored all the values in it and dropped it later.

Actually what ever i return will in turn will be stored in datatable(asp.net) and later on processed.

thanks again all.
regards
cmrhema
Nov 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: mingzhen | last post by:
Hi, I have a problem here when I code stored procedure to manipulate data in database. My idea is that if I can save all data I get in some arrays I should be able to manipulate the arrays...
4
by: Kevin Gibbons | last post by:
Hi, I am trying to concatenate 2 text fields to update a sql db column by using: UPDATE Messages SET private_messages = private_messages || @newmessage But the stored procedure I am using...
0
by: Luis Esteban Valencia | last post by:
Hello I am in big troubles trying to concatenate this I have a datalist Private Sub llenardatalistpartidos(ByVal idfase As Int32, ByVal iddeporte As Int32) Dim dr As sqldatareader dr =...
2
by: Rico | last post by:
Hello, I'm wondering if there is a way to concatenate two fields or a field and a string value in a single field in a view? Where in Access I might write; & " (m3)" as TotalVolume is...
4
by: Wladimir Borsov | last post by:
Ok, think of let say 10 different web pages on the internet. Each of them are usual html web pages. Nothing special. What I want to do now is to create a new meta resp. grouping web page which...
6
by: Sheldon | last post by:
Hi, I am trying to build a large array using concatenate function in python. So as I loop over the number of arrays, of which there are 12 (4 down and 3 across), I create 3 long arrays by...
10
by: tlyczko | last post by:
Hello, We have Access databases (backends) that will eventually be consolidated into a SQL Server database, to facilitate data reporting, analysis, etc. Some queries in one Access database...
12
by: parth | last post by:
Hi I want to achieve the following transformation of data using a stored procedure. Source col1 col2(varchar) -------------------------
3
by: nandan | last post by:
Yes. My client has a proxy server. That much i know. In my application I make two kinds of calls that are affected by the proxy server I finally got the webservice call working. But my...
10
by: Aaron Hoffman | last post by:
Hello, I'm hoping someone might be able to offer some guidance to my problem. I have one query in MS Access which consists of 2 tables joined by a SEQUENCE_ID. By joining the two tables I am...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.