By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,266 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,266 IT Pros & Developers. It's quick & easy.

SQL Query

P: 92
Anyone suggest me how to store data in SQL Server 2005 as

Book - ID
-------------
Book - 1
Book - 2
.......
Book - n

Book - (1,2,3...) must be in auto increment value. Is there any query to insert this data, or any procedure. Suggest me the query or procedure to code, through SQL 2005. Please explain this carefully.....

Thanks in Advance.
Apr 9 '09 #1
Share this Question
Share on Google+
4 Replies


ck9663
Expert 2.5K+
P: 2,878
Yes.

Create an identity column to handle your auto-increment column. Add a computed column to store your BOOK ID.


--- CK
Apr 9 '09 #2

P: 92
Thank U,

Auto-increment column, increase the value by 1,2, 3.... and Computed column->formula, Showing some error and i dont know what to give in formula column. Please explain me more with some example.
I need to increment by Book-1,Book-2...Book-n, not 1,2,3... n.
Apr 13 '09 #3

P: 92
@ck9663
Thank U,

Auto-increment column, increase the value by 1,2, 3.... and Computed column->formula, Showing some error and i dont know what to give in formula column. Please explain me more with some example.
I need to increment by Book-1,Book-2...Book-n, not 1,2,3... n.
Apr 17 '09 #4

Delerna
Expert 100+
P: 1,134
Limno
Why do you need to store it as
Book-1
Book-2
...

It seems that having "Book-" in every row is a waste of space.

If you have the table with an auto incrementing field as suggested by CK
achieves what you are asking for.

Expand|Select|Wrap|Line Numbers
  1. Table tblMyBooks
  2. ID  TITLE       ETC........
  3. 1   ghfgteuj
  4. 2   bjhja
  5. 3   dsw
  6.  
If you really want it to be displayed as you describe then you do that in a query and base your front end off the query
Expand|Select|Wrap|Line Numbers
  1. SELECT 'Book-' + convert(varchar(10),ID) as ID,Title,Etc....
  2. FROM tblMyBooks
  3.  
The above query would return my sample data as
Expand|Select|Wrap|Line Numbers
  1. Book-1      ghfgteuj
  2. Book-2      bjhja
  3. Book-3      dsw
  4.  
Alternatively, you could add the "Book-" to the ID in the front end application itself.
Apr 20 '09 #5

Post your reply

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