'How to union queries with different data types?

I have a query that resembles the code below:

SELECT A, B, Cd
INTO #Temp
FROM Table1

UNION

SELECT A, B, C
FROM Table2

UNION

SELECT A, B, C
FROM Table3

Cd has the same values as C, however Cd is a float whereas C is nvarchar(255). I have tried Cast() and Convert() and Try_Convert() on Cd, but I keep getting:

Error converting data type nvarchar to float.



Solution 1:[1]

You can simply do it like that:

    componentDidMount() {
        const baseUrl = `https://........`;
        fetch(baseUrl)
        .then((response) => response.json())
        .then(result => {
            this.setState({ names: result.data});
        });
    }

Solution 2:[2]

getData is an async function that you syncronize your fetch call inside. So it returns a promise. You're console logging inside that function after response fetched. So it logs the data.

You can think it as Fetch function that you use, you're awaiting it because it's a async function and you should await for the response. It's the same for the getData too. No matter how you wait, use then or await.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Borni.Mr
Solution 2 acbay