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 do I convert int to nvarchar and vice versa
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rsegecin
Yak Posting Veteran

United Kingdom
82 Posts

Posted - 07/04/2007 :  21:47:30  Show Profile  Reply with Quote
Hi guys, how are you? I was wondering how I do to convert int to nvarchar and vice versa?
Thank you very much.

khtan
In (Som, Ni, Yak)

Singapore
17681 Posts

Posted - 07/04/2007 :  21:52:09  Show Profile  Reply with Quote
use the convert() function

convert(nvarchar(10), 12)

convert(int, N'12')


Please refer to the Books OnLine (BOL) or http://msdn2.microsoft.com/en-us/library/ms187928.aspx for more details


KH
Time is always against us

Go to Top of Page

rsegecin
Yak Posting Veteran

United Kingdom
82 Posts

Posted - 07/04/2007 :  21:53:42  Show Profile  Reply with Quote
Thank you very much khtan.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22772 Posts

Posted - 07/04/2007 :  23:54:19  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
I am interested to know why you want to switch between these two

Madhivanan

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

Arijit
Starting Member

25 Posts

Posted - 07/05/2007 :  00:08:27  Show Profile  Reply with Quote
In case of int -> nvarchar it is fine but when you try to convert the nvarchar -> int, on that time nvarchar should contain numeric values.

Arijit
Go to Top of Page

facestheband
Starting Member

USA
6 Posts

Posted - 07/05/2007 :  00:24:01  Show Profile  Visit facestheband's Homepage  Reply with Quote
You can also use the cast function i.e.

cast(value as varchar) or cast(value as int)
Go to Top of Page

rsegecin
Yak Posting Veteran

United Kingdom
82 Posts

Posted - 07/05/2007 :  02:16:33  Show Profile  Reply with Quote
Well I'm doing forum right now and there is the threads that people can subscribe for them, as we've here in SQLTeam. The user who will create a new thread will be already subscribed for it. So in my database I rather create a field in the threads table to put the user's ids, separated by semi colons, from those who are subscribed. As the creator of this thread will be already subscribed so I had to convert the user_id from him to a string and put it on the subscriber’s field. That is for not just created a new table with just the subscribers. What do you think? Would be rather creating a new table or not?

Thank you for the regard.
Go to Top of Page

AndrewMurphy
Flowing Fount of Yak Knowledge

Ireland
2916 Posts

Posted - 07/05/2007 :  07:17:03  Show Profile  Reply with Quote
what happens with very popular threads...you end up with very large semi-colon seprated lists??
what's wrong with having a child record...one per subscription?...far simpler...far more "db normal" as well.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22772 Posts

Posted - 07/05/2007 :  09:32:58  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote

http://www.datamodel.org/NormalizationRules.html


Madhivanan

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

rsegecin
Yak Posting Veteran

United Kingdom
82 Posts

Posted - 07/05/2007 :  12:08:26  Show Profile  Reply with Quote
Thank you very much Andrew Murphy for you opinion and madhivana for the link, today yet I gonna read it and post here again.
This peace of text I just cutted from the last thread I made here in SQL Team:
Well I'm learning T-SQL everything all by my self, I'm struggling in web developer and I'm not working with team or anyone to have a point of reference, so if you saw my code you would be shocked, cuz it's a kind of nhacc... but the import think that they are working =D lol. so never mind.
But I think is time for me to change. Thank you for your advices again. =D
Go to Top of Page

rsegecin
Yak Posting Veteran

United Kingdom
82 Posts

Posted - 07/05/2007 :  23:35:19  Show Profile  Reply with Quote
Yea I will create a new table with the subscribers for each thread. I knew that would be more easier do manage but I don't know why creating a new table had made me fell uncomfortable. Reading the article about data model that madhivanan pointed I came up with a problem. In this article mention about avoid duplicated data, but if creating duplicate data would help a lot when you make a query would you still not duplicate it? The case is when the user enter in the forum he would see the first user who created the thread and the last who posted there. I made a threads table that update a field, which correspond the last user who posted there. I know it's redundant because I could not have this field but would be more difficult to make the query, because would have to see all the posts made for each thread order by date, take last and the first one of each thread, and then give them back, beside of getting straight to the point. Well I had made my decision but it made me confused, I can handle the both but by your experience what seem to be the best?

Thank you very much indeed.
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.08 seconds. Powered By: Snitz Forums 2000