Sunday, March 11, 2012
Cannot use the OUTPUT option when passing a constant to a stor
without any success because I keep getting a syntax error.
My Code:
bcp "Select Replace(Str(UNITNUM, 12, 0), ' ', '0') FROM PICUadmissions
WHERE Admit_Date>'2005-06-01' and Admit_Date<'2005-07-01'" queryout
"I:\sttr\STTRLabsIn.txt" -c -T
go
The Error: "incorrect syntax near queryout"
Thanks reading my message.
Chieko
"Dan Guzman" wrote:
> Since your BCP source is a query rather than a table/view, you need to
> specify 'queryout' instead of 'out'.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "chieko" <chieko@.discussions.microsoft.com> wrote in message
> news:A82B768C-9367-447E-81DE-8EBFFAFBD62C@.microsoft.com...
>
>BCP is a command-prompt utility, not a Transact-SQL statement. You need to
run the command from a Windows command line rather than Query Analyzer.
Hope this helps.
Dan Guzman
SQL Server MVP
"chieko" <chieko@.discussions.microsoft.com> wrote in message
news:1CADD6C5-9A7A-4CD7-BFC4-6FC2366756F9@.microsoft.com...
>I just checked the message today. I have tried the queryout method but
> without any success because I keep getting a syntax error.
>
> My Code:
> bcp "Select Replace(Str(UNITNUM, 12, 0), ' ', '0') FROM PICUadmissions
> WHERE Admit_Date>'2005-06-01' and Admit_Date<'2005-07-01'" queryout
> "I:\sttr\STTRLabsIn.txt" -c -T
> go
> The Error: "incorrect syntax near queryout"
> Thanks reading my message.
> Chieko
> "Dan Guzman" wrote:
>|||Thanks,
"Dan Guzman" wrote:
> BCP is a command-prompt utility, not a Transact-SQL statement. You need t
o
> run the command from a Windows command line rather than Query Analyzer.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "chieko" <chieko@.discussions.microsoft.com> wrote in message
> news:1CADD6C5-9A7A-4CD7-BFC4-6FC2366756F9@.microsoft.com...
>
>
Sunday, February 19, 2012
Cannot set Default value for column using "Alter column"
In SQL Server 2005 (Mgmt Studio): according to BOL, the syntax to set a default value for an existing column is:
ALTER TABLE MyCustomers ALTER COLUMN CompanyName SET DEFAULT 'A. Datum Corporation'
However, when I Check:
alter table CommissionPayment alter column Amount Set Default 0
I get the error message:
"Incorrect syntax near the keyword 'Set'."
No other combinations of this syntax work.
Help! What am I missing?? DEFAULT is not a column property in T-SQL -- it's actually implemented as a constraint. The correct syntax is: CREATE TABLE #x (id int) ALTER TABLE #x ADD CONSTRAINT DF_id DEFAULT (0) FOR id Where in BOL did you see that syntax? -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <Karl Kaiser@.discussions.microsoft.com> wrote in message news:a5caf4ff-8884-4383-960f-b4f61aad2da2@.discussions.microsoft.com...Well here's one of those excruciatingly simple obstacles:In SQL Server 2005 (Mgmt Studio): according to BOL, the syntax to set a default value for an existing column is:[b]ALTER TABLE MyCustomers ALTER COLUMN CompanyName SET DEFAULT 'A. Datum Corporation'[/b]However, when I Check:[b]alter table CommissionPayment alter column Amount Set Default 0[/b]I get the error message:[b]"Incorrect syntax near the keyword 'Set'."[/b]No other combinations of this syntax work.Help! What am I missing?|||The syntax you saw was for SQL Server Mobile Edition. It is not applicable for the other SQL Server editions. So the correct way is to add default as a constraint using syntax posted by Adam.