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
 How to insert number ?

Author  Topic 

teamjai
Yak Posting Veteran

52 Posts

Posted - 2012-10-09 : 05:25:46
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
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-09 : 06:50:16
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

190 Posts

Posted - 2012-10-09 : 06:51:50
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
   

- Advertisement -