For example I want to do something like this :
//if the Column type is nvarchar
//do something
//if the Column type is int
//do something
EDITED:
for example :
i have a table with columns(col1 is int,col2 is nvarchar),and i have data in this table,for example
col1 : 1,2,3,4,NULL and col2 : a,b,d,f,E,NULL
now i want to fill NULL data of col1 with 0 and NULL data of col2 with ” “
If you know the table and the column name, then:
However note that you won’t be able to declare the same variable name with different data types this way, even if SQL Server will only ever reach one of them. You will get something like:
If you know the name of the table then you can build a dynamic SQL statement like you propose as follows (note that this only covers a subset of types – but should give you the idea):
I don’t know how you could even dream of doing this without dynamic SQL. And ugh, that’s a lot of work to prevent your presentation tier from having to deal with NULLs. That is probably the better place to deal with this.