Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Auto Generate Series?

Author  Topic 

nickjack
Starting Member

34 Posts

Posted - 2008-11-07 : 01:29:07
Hi,
I need a Series Like Q1, Q2 and So on....

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-07 : 01:37:35
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57069


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-07 : 01:42:22
Create an identity column and computed column based on identity column to append the series aplhabet.
Go to Top of Page

nickjack
Starting Member

34 Posts

Posted - 2008-11-07 : 01:48:29
sample code ?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-07 : 01:58:25
[code]CREATE TABLE #Temp
(ID int identity(1,1),
Test varchar(11),
Seq AS 'Q'+CAST(ID as varchar(4))
)
INSERT INTO #Temp (Test)
SELECT 'val1' union all
SELECT 'val2' union all
SELECT 'val3' union all
SELECT 'val4' union all
SELECT 'val5'

select * from #Temp
drop table #Temp

output
----------------------
ID Test Seq
1 val1 Q1
2 val2 Q2
3 val3 Q3
4 val4 Q4
5 val5 Q5
[/code]
Go to Top of Page

nickjack
Starting Member

34 Posts

Posted - 2008-11-07 : 04:02:38
Hi
I have table

Col1 Col2 Col3
ID QuestionNo QuestionText

1 Q1 Hi?


and Also need a Procedure who insert value like Q1,Q2 and so on.. only Question No
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-07 : 04:13:08
quote:
Originally posted by nickjack

Hi
I have table

Col1 Col2 Col3
ID QuestionNo QuestionText

1 Q1 Hi?


and Also need a Procedure who insert value like Q1,Q2 and so on.. only Question No



you are not giving enough information


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

nickjack
Starting Member

34 Posts

Posted - 2008-11-07 : 07:02:34
In my table i have 3 column say c1,c2,c3

C1 C2 C3
Id QuestionNumber QuestionText


what i need:
1)A procedure ?
2)which makes my C2 column auto incremented in a form Q1, Q2,Q3 and so on.....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-07 : 07:07:33
DId you see query i posted. Create a table as suggested then simply use a procedure to insert values just as i did.
Go to Top of Page

nickjack
Starting Member

34 Posts

Posted - 2008-11-08 : 01:46:18
And If i need Like Q001 in Place Of Q1 then
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-08 : 03:53:55
CREATE TABLE #Temp
(ID int identity(1,1),
Test varchar(11),
Seq AS 'Q'+ RIGHT('00' + CAST(ID as varchar(4)),3)
)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-10 : 00:40:02
quote:
Originally posted by nickjack

And If i need Like Q001 in Place Of Q1 then


Also did you read the link I posted?


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -