Simple question on a SQL create table - sql-server-2005

I was actually in process of creating a sample table in my test database when somehow I missed out on proper syntax and came up with this statement for create table -
CREATE TABLE A (id as INT, column1 as nvarchar(10))
and when I tried to execute this statement, I got the error below -
'nvarchar' is not a recognized built-in function name.
Altough, I found that I should not have used "as" in the column declaration and corrected it, I am now curious on why I got this error for only nvarchar and not for INT.
Also why this error instead of a incorrect syntax or something like that.
Thanks in advance.

AS is used to define computed columns. Therefore SQL Server expects an expression here, and this "looks" like a function call.
Computed columns info on MSDN for SQl Server 2005

Related

Data Type Conversion causing error in SSIS Package

I have an SSIS package that has a step that creates a temp table using a Execute SQL Task.
Inside of this query I have a case statement that is something like:
Cast(Case
When billing_address is Like '%DONOTUSE%' Then 1
When billing_address is Like '%DONTUSE%' Then 1
Else 0
End as nvarchar)DoNotUseAccounts
I have an update statement in a different Execute SQL Task that is like this:
Update #StatementAccounts
Set Issues = Issues + ' - Do Not Use Account'
Where Product In ('prod1','prod2','prod3','prod4')
And DoNotUseCustomer= 1
When executing the package I am receiving an error: "Error: String or binary data would be truncated."
Am I using the wrong data type?
Does the Update statement need to be cast/converted as well?
Any guidance would be helpful.
I have tried using datatype int, numeric, and Casting the update statement as an int as well.
You have one of two possible issues here.
1) You have an explicit CREATE TABLE #StatementAccounts statement where you're defining Issues as NVARCHAR with no length specified, in which case it's one character, or with a length that's too small to accommodate the additional characters that you're trying to append with your UPDATE statement.
FIX: Make the declaration at least len( ' - Do Not Use Account') characters longer.
2) Much more likely from the sound of things, you're using a SELECT...INTO #StatementAccounts statement and letting SQL Server define your data types for you. In this case, it's setting Issues to be just big enough to accommodate the largest value in that initial statement.
FIX: Issue an explicit CREATE TABLE #StatementAccounts statement and declare appropriately sized data types, then change the SELECT...INTO to an INSERT INTO.

'Syntax error: Expected ")"' in BigQuery

I want to execute the following SQL statement on BigQuery:
create table TMSPCBTDZOP000(
ART_ID VARCHAR(18),
LND_ID VARCHAR(3),
ART__BEZ VARCHAR(60),
ART_ANZ_ID VARCHAR(18))
I got the following error message:
Error: Syntax error: Expected ")" or "," but got "(" at [2:24]
I tried both legacy and standard SQL.
We are currently trying to use BigQuery as a data source for our reporting software (MicroStrategy) and it fails with the error shown above. The same error appears if I directly fire this SQL statement in bq. How can I fix this?
VARCHAR is not a supported data type; see the data types documentation. Use STRING instead:
create table TMSPCBTDZOP000 (
ART_ID STRING,
LND_ID STRING,
ART__BEZ STRING,
ART_ANZ_ID STRING
)
You need to use standard SQL for this, and you probably need to qualify TMSPCBTDZOP000 with the name of the dataset, e.g. dataset.TMSPCBTDZOP000.
I think you are looking something like mentioned in old thread here
Create table SQL syntax in Google Bigquery
I found it useful and this may help you how to create a table in bigquery.
Cheers,

Can I use question marks in SQLite table column name?

When I try to create a table with the following as a column name: "Admin?" in my SQLite Database, I get a SQL error saying:
SQL error or missing database (near "?": syntax error)
Here is my SQL statement:
CREATE TABLE test (admin? TEXT PRIMARY KEY);
I am assuming I cannot have question marks inside column names, but I cannot find any documentation about it. If this is the issue, is there any workaround here, or a better solution? Also, I am creating the table from Kotlin code, so I am not sure if that has any effect on it.
Escape the column name:
CREATE TABLE test ("admin?" TEXT PRIMARY KEY);

how to pull a column named "NUMBER" from Oracle through Ms Query in Excel

I know, I know...The column shouldn't be named "NUMBER", but it was here before I was, and I can't change it for now. At the moment, I only have read access to this database, and I was told it would be changed...soonish...
I've tried referencing it as Table."NUMBER" and that works when querying directly from Oracle, but for some reason, I still get the infamous ORA-01747: invalid user.table.column, table.column, or columns specification error when I reference it that way in MS Query. I also tried Table.""NUMBER"", "Table."NUMBER"", Table.'"NUMBER"', and 'Table."NUMBER"', but each of these gave me an error from MS Query saying it wasn't expecting the punctuation in the select column list.
Does this have something to do with the way MS Query handles double quotes? Is there any way to make sure that the double quotes around NUMBER make it to Oracle without MS Query throwing an error?
My query is really simple...except for this part.
Select Table."NUMBER"
From Table
Thanks in advance for any help.
try
SELECT table."NUMBER" AS a_number FROM table
or create a view referencing the table and rename the column as required
Aliases solve a lot of problems with names. I suspect that the issue you were having is not with running the query in Oracle but the result that comes back from Oracle. An alias allows the result set to be usable by Access.

SQL select from table with alias (Oracle9i)

According to Oracle documentation for statement SELECT it should be possible to alias table names with aliases without or with keyword AS. However, aliasing tables with keyword AS leads to error:
ORA-00933: SQL command not properly ended
For example, the following statement fails with the above error:
SELECT COUNT(*) FROM MY_TABLE AS A;
Once keyword AS is removed it executes as expected.
Could anyone please comment on this. Is there a way to make the application of AS for table aliasing work?
P.S. I'm using a code generation utility that translate some Java code into SQL statements at runtime. This utility enforces the use of aliases with AS.
Oracle does not accept AS for table aliases and I see no way to make it work.
Can't you do anything in Java? AS for column aliases is optional in Oracle, so you could look for all " AS " in the generated string and remove them (thus removing AS for column aliases as well as for table aliases). Is this an option?