SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to insert number ?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

teamjai
Starting Member

India
44 Posts

Posted - 10/09/2012 :  05:25:46  Show Profile  Reply with Quote
Dear all,

I am using SQL server 2008.
I am trying to insert data into a tables,
I don't know how to insert number in the below format.
please help me.
Table 1:
Seq.No
--------
1:1
2:2
3:3
.
.
n:n

Table 2:

Seq.No
-------
1:1
1:2
.
.
1:n

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/09/2012 :  06:50:16  Show Profile  Reply with Quote
If the column into which you are inserting the number has a numeric data type (INT, BIGINT etc.), you cannot insert a value such as 1:1 into that column. To be able to do that, the column has to be of character type (such as VARCHAR, NCHAR etc.).

It may be better if you do not try to make the column character type. Instead, one approach you might consider is to have two columns, both of numeric type - for example, SeqNo column and SubSeqo column. Then, you would insert the part to the left of the colon in the Seq No column and the part to the right in the SubSeqNo column.
Go to Top of Page

sql-programmers
Posting Yak Master

USA
190 Posts

Posted - 10/09/2012 :  06:51:50  Show Profile  Visit sql-programmers's Homepage  Reply with Quote
Hi,

You can not store values like 1:1, 1:2...n:n in the number field.

You can achieve if you define as varchar field in the table. When you insert new record you need to get maximum value

of the sequence or sub-sequence number then concatenate the both and finally store the value in the varchar field.

It more difficult....


But if you would like this field to make as primary field.

This is not a normalization method. instead of store like 1:1, 1:2 define two columns in the table to store

the sequence no and sub-sequence number with primary key.

It will be more comfortable and normalized.



SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000