Forum Discussion

vocono's avatar
vocono
Copper Contributor
Dec 05, 2023

Hyperlink and Varchar Data Types in the Same Column

I need to import data from an Exell spreadsheet. Several columns have hyperlinks and text data types. Is it possible to combine these types in a SQL column? If so, how is it done?

 

Thank you for any advice you may offer.

 

--Bob

2 Replies

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    vocono For Excel import the best data type & size to use is nvarchar(255), it can store any Excel content/text/URL etc.

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    vocono 

     

    Hi, Bob.

     

    SQL has no concept of a URL data type, only character-based (ASCII and UNICODE variations):

     

     

    Additionally, in relational data design (specifically, normalisation), you should (nearly a "must") not store multiple values inside a single column.

     

    In a well-designed model, the URL value would be stored in one column while the descriptive name of the URL (i.e. the alt text) would be stored in another column.

     

    There's a lot of differences between a client-facing application like Excel and an enterprise data platform like SQL Server. This is just one of them.

     

    What you will find is that where SQL stores something like a URL as a text datatype, Excel can intelligently detect that the text represents a URL and dynamically format it as such. And while I'm not much use in Excel, it wouldn't surprise me if there's a way (taking a guess at the HYPERLINK function listed below) to take that one step further and include the alt text so that the "nice to read" version is presented using the two columns from the underlying SQL table/view. But you might want to explore that in the Excel community rather than here.

     

     

    Cheers,

    Lain

Resources