Abdallah Abdulrahman
Abdallah Abdulrahman

Reputation: 11

Storing both string and integer in one column together

I would like to store in a column, a userID which goes with this format "ED25" Which data type should I use? Additional info to make that possible is welcomed.

Upvotes: 0

Views: 2462

Answers (3)

shA.t
shA.t

Reputation: 16958

I think you need to use a numeric data type like bigint.

So, I suggest you to use a mixed mode of varbinary and bigint like this:

SELECT CONVERT(bigint, CONVERT(varbinary,'ED25'))

Result:

1162097205

And for decoding it:

SELECT CONVERT(varchar, CONVERT(varbinary, 1162097205))

Upvotes: 0

Wishaal Khan
Wishaal Khan

Reputation: 135

You should use varchar(50). You can combine ED and # using C# or other language of your choice. In C# you will generate an SQL command like:

INSERT INTO yourtablename(ED) VALUES ('ED"+your_int.ToString()+"')

Upvotes: 0

Renzo
Renzo

Reputation: 27424

Actually you are using strings, so you should use either a varchar(n) or text.

If you use PostgreSQL you can use text, otherwise you can use varchar(n), where n is the maximum possible size of your strings.

Upvotes: 1

Related Questions