-
Determining, then changing, a column's data type
I get SQL Server 2008 table from another department once a month. This table has grown from about 50 or so fields to almost 200.
Many of these fields get created as FLOAT. This is a result of the download/creation process the department that gives me the table goes through. I have no control over that.
When the table was pretty small, I would simply go through it and do an ALTER TABLE ALTER COLUMN etc etc and change the type from FLOAT to DECIMAL, which is what I need.
This has become a bit cumbersome, so I decided to see if I could write a SPROC that would do all of this for me.
Step number one would be to determine which fields are FLOAT. To do that, I cobbled this together from two or three different posts I found in the internet
Code:
SELECT
clmns.name AS [Name],
usrt.name AS [DataType],
ISNULL(baset.name, N'') AS [SystemType]
FROM <name of my table>
CAST(
CASE
WHEN baset.precision = 'float') THEN
'Yes' ELSE 'No'
END
I figured once I can pick out those fields, I could add the ALTER TABLE code to change them, then put the whole thing into a SPROC.
However, Step 1 isn't even working. The code I'm using, as posted above, gives me a "syntax error near the keyword case"
What am I doing wrong?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|