Monday, March 26, 2012
how to change permission via t-sql
I have a database that has about 50 tables. I have a user group assigned
to the database. I want them to be able to insert/update but not delete. The
only way I have seen is to go into the table permissions and change the
permissions. Is there an easier way via t-sql? Thanks in advance.
JakeRun this, verify that the output will do what you want and then execute the
output:
SELECT 'GRANT INSERT, UPDATE ON ' + TABLE_NAME + ' TO YourUserGroup' FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'base table'
--
Keith
"Jake" <rondican@.hotmail.com> wrote in message
news:uyD6ueAoEHA.1456@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I have a database that has about 50 tables. I have a user group
assigned
> to the database. I want them to be able to insert/update but not delete.
The
> only way I have seen is to go into the table permissions and change the
> permissions. Is there an easier way via t-sql? Thanks in advance.
> Jake
>|||Keith,
Thanks very much for the info
"Keith Kratochvil" <sqlguy.back2u@.comcast.net> wrote in message
news:efMdMqAoEHA.2588@.TK2MSFTNGP12.phx.gbl...
> Run this, verify that the output will do what you want and then execute
the
> output:
> SELECT 'GRANT INSERT, UPDATE ON ' + TABLE_NAME + ' TO YourUserGroup' FROM
> INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'base table'
> --
> Keith
>
> "Jake" <rondican@.hotmail.com> wrote in message
> news:uyD6ueAoEHA.1456@.TK2MSFTNGP10.phx.gbl...
> > Hello,
> >
> > I have a database that has about 50 tables. I have a user group
> assigned
> > to the database. I want them to be able to insert/update but not delete.
> The
> > only way I have seen is to go into the table permissions and change the
> > permissions. Is there an easier way via t-sql? Thanks in advance.
> >
> > Jake
> >
> >
>
how to change permission via t-sql
I have a database that has about 50 tables. I have a user group assigned
to the database. I want them to be able to insert/update but not delete. The
only way I have seen is to go into the table permissions and change the
permissions. Is there an easier way via t-sql? Thanks in advance.
Jake
Run this, verify that the output will do what you want and then execute the
output:
SELECT 'GRANT INSERT, UPDATE ON ' + TABLE_NAME + ' TO YourUserGroup' FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'base table'
Keith
"Jake" <rondican@.hotmail.com> wrote in message
news:uyD6ueAoEHA.1456@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I have a database that has about 50 tables. I have a user group
assigned
> to the database. I want them to be able to insert/update but not delete.
The
> only way I have seen is to go into the table permissions and change the
> permissions. Is there an easier way via t-sql? Thanks in advance.
> Jake
>
|||Keith,
Thanks very much for the info
"Keith Kratochvil" <sqlguy.back2u@.comcast.net> wrote in message
news:efMdMqAoEHA.2588@.TK2MSFTNGP12.phx.gbl...
> Run this, verify that the output will do what you want and then execute
the
> output:
> SELECT 'GRANT INSERT, UPDATE ON ' + TABLE_NAME + ' TO YourUserGroup' FROM
> INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'base table'
> --
> Keith
>
> "Jake" <rondican@.hotmail.com> wrote in message
> news:uyD6ueAoEHA.1456@.TK2MSFTNGP10.phx.gbl...
> assigned
> The
>
sql
Monday, March 12, 2012
How to capture an error message in T-SQL?
log table.
I know that I can get error # from ERROR variable.
Where can I get the text, that consist information aboout objects that
caused problem?
Example
create procedure MyProc as
DECLARE Err int;
DECLARE ErrMsg varchar(256)
DELETE FROM ParentTable where ID=@.P_ID;
set @.Err=ERROR;
if @.Err!=0
begin
set @.ErrMsg=''?
insert into MyLog values (getdate(),'MyProc',@.Err,@.ErrMsg);
end;
go;
I expect to see in MyLog something like `Foreign key violation, child
record found, constraint "FK_ChildTable"`,
or "No permission to delete for table "ParentTable"`
or whatever I would see if I execute this TSQL in SQL Analyzer manually.
BTW, are all of such errors being written into some standard MSSQL log?
Is it SysLog or where?
Thanks,
MarkMark
Unfortunatly you cannot capture such kind of errors in current version.I
know with Yukon will introduce error handle like try--catch but cannot give
more details at this time.
On other hand look at my example helps you to solve the problem (Modify it
for your needs)
create table parent
(
col int not null primary key
)
go
insert into parent values (1)
go
create table child
(
col int not null primary key,
col1 int not null --references parent (col)
)
go
insert into child(col,col1) values (1,1)
insert into child(col,col1) values (2,1)
go
create trigger my_tr on parent for delete
as
if exists ( select * from child c join deleted d on c.col1=d.col)
raiserror ('Cannot delete',16,1)
go
delete parent where col=1
go
drop table child
drop table parent
"Mark Malakanov" <markmal@.rogers.com> wrote in message
news:402674CD.4080101@.rogers.com...
> I need to capture an actual error message and place this record into a
> log table.
> I know that I can get error # from ERROR variable.
> Where can I get the text, that consist information aboout objects that
> caused problem?
> Example
> create procedure MyProc as
> DECLARE Err int;
> DECLARE ErrMsg varchar(256)
> DELETE FROM ParentTable where ID=@.P_ID;
> set @.Err=ERROR;
> if @.Err!=0
> begin
> set @.ErrMsg=''?
> insert into MyLog values (getdate(),'MyProc',@.Err,@.ErrMsg);
> end;
> go;
> I expect to see in MyLog something like `Foreign key violation, child
> record found, constraint "FK_ChildTable"`,
> or "No permission to delete for table "ParentTable"`
> or whatever I would see if I execute this TSQL in SQL Analyzer manually.
> BTW, are all of such errors being written into some standard MSSQL log?
> Is it SysLog or where?
> Thanks,
> Mark
>|||> Unfortunatly you cannot capture such kind of errors in current version.I
> know with Yukon will introduce error handle like try--catch but cannot
give
> more details at this time.
See http://msdn.microsoft.com/msdnmag/i...on/default.aspx
for new Yukon enhancements in error handling with the TRY/CATCH construct
sincerely,
--
Sebastian K. Zaklada
Skilled Software
http://www.skilledsoftware.com
This posting is provided "AS IS" with no warranties, and confers no rights.
************************************
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation|||Uri, thank you.
I wrote FK code just for example.
Question was about error handling and capturing of error message text.
Mark
Uri Dimant wrote:
> Mark
> Unfortunatly you cannot capture such kind of errors in current version.I
> know with Yukon will introduce error handle like try--catch but cannot gi
ve
> more details at this time.
> On other hand look at my example helps you to solve the problem (Modify it
> for your needs)
> create table parent
> (
> col int not null primary key
> )
> go
> insert into parent values (1)
> go
> create table child
> (
> col int not null primary key,
> col1 int not null --references parent (col)
> )
> go
> insert into child(col,col1) values (1,1)
> insert into child(col,col1) values (2,1)
> go
> create trigger my_tr on parent for delete
> as
> if exists ( select * from child c join deleted d on c.col1=d.col)
> raiserror ('Cannot delete',16,1)
> go
> delete parent where col=1
> go
> drop table child
> drop table parent
>
>
>
> "Mark Malakanov" <markmal@.rogers.com> wrote in message
> news:402674CD.4080101@.rogers.com...
>
>
>|||Uri, thank you.
I wrote FK code just for example.
Question was about error handling and capturing of error message text.
Mark
Uri Dimant wrote:
> Mark
> Unfortunatly you cannot capture such kind of errors in current version.I
> know with Yukon will introduce error handle like try--catch but cannot gi
ve
> more details at this time.
> On other hand look at my example helps you to solve the problem (Modify it
> for your needs)
> create table parent
> (
> col int not null primary key
> )
> go
> insert into parent values (1)
> go
> create table child
> (
> col int not null primary key,
> col1 int not null --references parent (col)
> )
> go
> insert into child(col,col1) values (1,1)
> insert into child(col,col1) values (2,1)
> go
> create trigger my_tr on parent for delete
> as
> if exists ( select * from child c join deleted d on c.col1=d.col)
> raiserror ('Cannot delete',16,1)
> go
> delete parent where col=1
> go
> drop table child
> drop table parent
>
>
>
> "Mark Malakanov" <markmal@.rogers.com> wrote in message
> news:402674CD.4080101@.rogers.com...
>
>
>|||Uri, thank you.
I wrote FK code just for example.
Question was about error handling and capturing of error message text.
Mark
Uri Dimant wrote:
> Mark
> Unfortunatly you cannot capture such kind of errors in current version.I
> know with Yukon will introduce error handle like try--catch but cannot gi
ve
> more details at this time.
> On other hand look at my example helps you to solve the problem (Modify it
> for your needs)
> create table parent
> (
> col int not null primary key
> )
> go
> insert into parent values (1)
> go
> create table child
> (
> col int not null primary key,
> col1 int not null --references parent (col)
> )
> go
> insert into child(col,col1) values (1,1)
> insert into child(col,col1) values (2,1)
> go
> create trigger my_tr on parent for delete
> as
> if exists ( select * from child c join deleted d on c.col1=d.col)
> raiserror ('Cannot delete',16,1)
> go
> delete parent where col=1
> go
> drop table child
> drop table parent
>
>
>
> "Mark Malakanov" <markmal@.rogers.com> wrote in message
> news:402674CD.4080101@.rogers.com...
>
>
>|||Sebastian, thanks,
It is good that Yukon can handle exceptions by TRY/CATCH. However I have
not found any Error Message Text capturing in examples. The error
messages are coded into the procedure, and are not actual messages from
Server. That unfortunate because in many cases the sole error code is
not enough, the object names associated with exception would be very
helpfull for further troubleshooting.
Mark
Sebastian K. Zaklada wrote:
> give
>
>
> See http://msdn.microsoft.com/msdnmag/i...ledsoftware.com
> This posting is provided "AS IS" with no warranties, and confers no rights
.
> ************************************
> SQL Source Control 2003 - for
> SQL Server Source Safe integration
> and custom databases documentation
>|||Mark,
> I need to capture an actual error message and place this record into a
> log table.
> I know that I can get error # from ERROR variable.
> Where can I get the text, that consist information about objects that
> caused problem?
You can't at the TSQL level.
> BTW, are all of such errors being written into some standard MSSQL log?
> Is it SysLog or where?
It depends whether the error is configured to. Check out the manage errors
dialog in EM and you'll see that checkbox. "Soft" errors are not written to
logs by default.
--
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=...ublic.sqlserver
"Mark Malakanov" <markmal@.rogers.com> wrote in message
news:402674CD.4080101@.rogers.com...
> I need to capture an actual error message and place this record into a
> log table.
> I know that I can get error # from ERROR variable.
> Where can I get the text, that consist information aboout objects that
> caused problem?
> Example
> create procedure MyProc as
> DECLARE Err int;
> DECLARE ErrMsg varchar(256)
> DELETE FROM ParentTable where ID=@.P_ID;
> set @.Err=ERROR;
> if @.Err!=0
> begin
> set @.ErrMsg=''?
> insert into MyLog values (getdate(),'MyProc',@.Err,@.ErrMsg);
> end;
> go;
> I expect to see in MyLog something like `Foreign key violation, child
> record found, constraint "FK_ChildTable"`,
> or "No permission to delete for table "ParentTable"`
> or whatever I would see if I execute this TSQL in SQL Analyzer manually.
> BTW, are all of such errors being written into some standard MSSQL log?
> Is it SysLog or where?
> Thanks,
> Mark
>
How to capture an error message in T-SQL?
log table.
I know that I can get error # from ERROR variable.
Where can I get the text, that consist information aboout objects that
caused problem?
Example
create procedure MyProc as
DECLARE Err int;
DECLARE ErrMsg varchar(256)
DELETE FROM ParentTable where ID=@.P_ID;
set @.Err=ERROR;
if @.Err!=0
begin
set @.ErrMsg=''?
insert into MyLog values (getdate(),'MyProc',@.Err,@.ErrMsg);
end;
go;
I expect to see in MyLog something like `Foreign key violation, child
record found, constraint "FK_ChildTable"`,
or "No permission to delete for table "ParentTable"`
or whatever I would see if I execute this TSQL in SQL Analyzer manually.
BTW, are all of such errors being written into some standard MSSQL log?
Is it SysLog or where?
Thanks,
MarkMark
Unfortunatly you cannot capture such kind of errors in current version.I
know with Yukon will introduce error handle like try--catch but cannot give
more details at this time.
On other hand look at my example helps you to solve the problem (Modify it
for your needs)
create table parent
(
col int not null primary key
)
go
insert into parent values (1)
go
create table child
(
col int not null primary key,
col1 int not null --references parent (col)
)
go
insert into child(col,col1) values (1,1)
insert into child(col,col1) values (2,1)
go
create trigger my_tr on parent for delete
as
if exists ( select * from child c join deleted d on c.col1=d.col)
raiserror ('Cannot delete',16,1)
go
delete parent where col=1
go
drop table child
drop table parent
"Mark Malakanov" <markmal@.rogers.com> wrote in message
news:402674CD.4080101@.rogers.com...
> I need to capture an actual error message and place this record into a
> log table.
> I know that I can get error # from ERROR variable.
> Where can I get the text, that consist information aboout objects that
> caused problem?
> Example
> create procedure MyProc as
> DECLARE Err int;
> DECLARE ErrMsg varchar(256)
> DELETE FROM ParentTable where ID=@.P_ID;
> set @.Err=ERROR;
> if @.Err!=0
> begin
> set @.ErrMsg=''?
> insert into MyLog values (getdate(),'MyProc',@.Err,@.ErrMsg);
> end;
> go;
> I expect to see in MyLog something like `Foreign key violation, child
> record found, constraint "FK_ChildTable"`,
> or "No permission to delete for table "ParentTable"`
> or whatever I would see if I execute this TSQL in SQL Analyzer manually.
> BTW, are all of such errors being written into some standard MSSQL log?
> Is it SysLog or where?
> Thanks,
> Mark
>|||> Unfortunatly you cannot capture such kind of errors in current version.I
> know with Yukon will introduce error handle like try--catch but cannot
give
> more details at this time.
See http://msdn.microsoft.com/msdnmag/issues/04/02/TSQLinYukon/default.aspx
for new Yukon enhancements in error handling with the TRY/CATCH construct
sincerely,
--
Sebastian K. Zaklada
Skilled Software
http://www.skilledsoftware.com
This posting is provided "AS IS" with no warranties, and confers no rights.
************************************
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation|||Uri, thank you.
I wrote FK code just for example.
Question was about error handling and capturing of error message text.
Mark
Uri Dimant wrote:
> Mark
> Unfortunatly you cannot capture such kind of errors in current version.I
> know with Yukon will introduce error handle like try--catch but cannot give
> more details at this time.
> On other hand look at my example helps you to solve the problem (Modify it
> for your needs)
> create table parent
> (
> col int not null primary key
> )
> go
> insert into parent values (1)
> go
> create table child
> (
> col int not null primary key,
> col1 int not null --references parent (col)
> )
> go
> insert into child(col,col1) values (1,1)
> insert into child(col,col1) values (2,1)
> go
> create trigger my_tr on parent for delete
> as
> if exists ( select * from child c join deleted d on c.col1=d.col)
> raiserror ('Cannot delete',16,1)
> go
> delete parent where col=1
> go
> drop table child
> drop table parent
>
>
>
> "Mark Malakanov" <markmal@.rogers.com> wrote in message
> news:402674CD.4080101@.rogers.com...
>>I need to capture an actual error message and place this record into a
>>log table.
>>I know that I can get error # from ERROR variable.
>>Where can I get the text, that consist information aboout objects that
>>caused problem?
>>Example
>>create procedure MyProc as
>>DECLARE Err int;
>>DECLARE ErrMsg varchar(256)
>>DELETE FROM ParentTable where ID=@.P_ID;
>>set @.Err=ERROR;
>>if @.Err!=0
>> begin
>> set @.ErrMsg=''?
>> insert into MyLog values (getdate(),'MyProc',@.Err,@.ErrMsg);
>> end;
>>go;
>>I expect to see in MyLog something like `Foreign key violation, child
>>record found, constraint "FK_ChildTable"`,
>>or "No permission to delete for table "ParentTable"`
>>or whatever I would see if I execute this TSQL in SQL Analyzer manually.
>>BTW, are all of such errors being written into some standard MSSQL log?
>>Is it SysLog or where?
>>Thanks,
>>Mark
>
>|||Uri, thank you.
I wrote FK code just for example.
Question was about error handling and capturing of error message text.
Mark
Uri Dimant wrote:
> Mark
> Unfortunatly you cannot capture such kind of errors in current version.I
> know with Yukon will introduce error handle like try--catch but cannot give
> more details at this time.
> On other hand look at my example helps you to solve the problem (Modify it
> for your needs)
> create table parent
> (
> col int not null primary key
> )
> go
> insert into parent values (1)
> go
> create table child
> (
> col int not null primary key,
> col1 int not null --references parent (col)
> )
> go
> insert into child(col,col1) values (1,1)
> insert into child(col,col1) values (2,1)
> go
> create trigger my_tr on parent for delete
> as
> if exists ( select * from child c join deleted d on c.col1=d.col)
> raiserror ('Cannot delete',16,1)
> go
> delete parent where col=1
> go
> drop table child
> drop table parent
>
>
>
> "Mark Malakanov" <markmal@.rogers.com> wrote in message
> news:402674CD.4080101@.rogers.com...
>>I need to capture an actual error message and place this record into a
>>log table.
>>I know that I can get error # from ERROR variable.
>>Where can I get the text, that consist information aboout objects that
>>caused problem?
>>Example
>>create procedure MyProc as
>>DECLARE Err int;
>>DECLARE ErrMsg varchar(256)
>>DELETE FROM ParentTable where ID=@.P_ID;
>>set @.Err=ERROR;
>>if @.Err!=0
>> begin
>> set @.ErrMsg=''?
>> insert into MyLog values (getdate(),'MyProc',@.Err,@.ErrMsg);
>> end;
>>go;
>>I expect to see in MyLog something like `Foreign key violation, child
>>record found, constraint "FK_ChildTable"`,
>>or "No permission to delete for table "ParentTable"`
>>or whatever I would see if I execute this TSQL in SQL Analyzer manually.
>>BTW, are all of such errors being written into some standard MSSQL log?
>>Is it SysLog or where?
>>Thanks,
>>Mark
>
>|||Uri, thank you.
I wrote FK code just for example.
Question was about error handling and capturing of error message text.
Mark
Uri Dimant wrote:
> Mark
> Unfortunatly you cannot capture such kind of errors in current version.I
> know with Yukon will introduce error handle like try--catch but cannot give
> more details at this time.
> On other hand look at my example helps you to solve the problem (Modify it
> for your needs)
> create table parent
> (
> col int not null primary key
> )
> go
> insert into parent values (1)
> go
> create table child
> (
> col int not null primary key,
> col1 int not null --references parent (col)
> )
> go
> insert into child(col,col1) values (1,1)
> insert into child(col,col1) values (2,1)
> go
> create trigger my_tr on parent for delete
> as
> if exists ( select * from child c join deleted d on c.col1=d.col)
> raiserror ('Cannot delete',16,1)
> go
> delete parent where col=1
> go
> drop table child
> drop table parent
>
>
>
> "Mark Malakanov" <markmal@.rogers.com> wrote in message
> news:402674CD.4080101@.rogers.com...
>>I need to capture an actual error message and place this record into a
>>log table.
>>I know that I can get error # from ERROR variable.
>>Where can I get the text, that consist information aboout objects that
>>caused problem?
>>Example
>>create procedure MyProc as
>>DECLARE Err int;
>>DECLARE ErrMsg varchar(256)
>>DELETE FROM ParentTable where ID=@.P_ID;
>>set @.Err=ERROR;
>>if @.Err!=0
>> begin
>> set @.ErrMsg=''?
>> insert into MyLog values (getdate(),'MyProc',@.Err,@.ErrMsg);
>> end;
>>go;
>>I expect to see in MyLog something like `Foreign key violation, child
>>record found, constraint "FK_ChildTable"`,
>>or "No permission to delete for table "ParentTable"`
>>or whatever I would see if I execute this TSQL in SQL Analyzer manually.
>>BTW, are all of such errors being written into some standard MSSQL log?
>>Is it SysLog or where?
>>Thanks,
>>Mark
>
>|||Sebastian, thanks,
It is good that Yukon can handle exceptions by TRY/CATCH. However I have
not found any Error Message Text capturing in examples. The error
messages are coded into the procedure, and are not actual messages from
Server. That unfortunate because in many cases the sole error code is
not enough, the object names associated with exception would be very
helpfull for further troubleshooting.
Mark
Sebastian K. Zaklada wrote:
>>Unfortunatly you cannot capture such kind of errors in current version.I
>>know with Yukon will introduce error handle like try--catch but cannot
> give
>>more details at this time.
>
> See http://msdn.microsoft.com/msdnmag/issues/04/02/TSQLinYukon/default.aspx
> for new Yukon enhancements in error handling with the TRY/CATCH construct
> sincerely,
> --
> Sebastian K. Zaklada
> Skilled Software
> http://www.skilledsoftware.com
> This posting is provided "AS IS" with no warranties, and confers no rights.
> ************************************
> SQL Source Control 2003 - for
> SQL Server Source Safe integration
> and custom databases documentation
>|||Mark,
> I need to capture an actual error message and place this record into a
> log table.
> I know that I can get error # from ERROR variable.
> Where can I get the text, that consist information about objects that
> caused problem?
You can't at the TSQL level.
> BTW, are all of such errors being written into some standard MSSQL log?
> Is it SysLog or where?
It depends whether the error is configured to. Check out the manage errors
dialog in EM and you'll see that checkbox. "Soft" errors are not written to
logs by default.
--
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Mark Malakanov" <markmal@.rogers.com> wrote in message
news:402674CD.4080101@.rogers.com...
> I need to capture an actual error message and place this record into a
> log table.
> I know that I can get error # from ERROR variable.
> Where can I get the text, that consist information aboout objects that
> caused problem?
> Example
> create procedure MyProc as
> DECLARE Err int;
> DECLARE ErrMsg varchar(256)
> DELETE FROM ParentTable where ID=@.P_ID;
> set @.Err=ERROR;
> if @.Err!=0
> begin
> set @.ErrMsg=''?
> insert into MyLog values (getdate(),'MyProc',@.Err,@.ErrMsg);
> end;
> go;
> I expect to see in MyLog something like `Foreign key violation, child
> record found, constraint "FK_ChildTable"`,
> or "No permission to delete for table "ParentTable"`
> or whatever I would see if I execute this TSQL in SQL Analyzer manually.
> BTW, are all of such errors being written into some standard MSSQL log?
> Is it SysLog or where?
> Thanks,
> Mark
>
Wednesday, March 7, 2012
How to Call a Script from T-SQL
I have a SQL script file with some statements in it. ... say c:\sai.sql. I want to call it through a T-SQL Procedure...Please let me know the process
SaiIf you DON'T need the script to run under the same SPID as your procedure you could always go the xp_cmdshell & i/osql route.
If you need to run under the same SPID, then you could load your script into a one row by one column table, select the text into a local variable and EXECUTE the variable.
How to calculate number of occurances of a character in a string
eg. abracadabra
no. of a's in the string : 5
Any Help is appreciated.select len(@.YourString)- len(replace(@.YourString, 'a', ''))
blindman
Friday, February 24, 2012
How to build this expression?
Greetings friends,
I have the following T-SQL CASE statement. I've spent the last 10 minutes trying to convert it to an expression in my derived column component but to no avail.
case
when f.etypeid < 10 then '000' + cast(f.etypeid as varchar)
when f.etypeid > 10 and f.etypeid < 100 then '00' + cast(f.etypeid as varchar)
else
'0' + cast(f.etypeid as varchar)
end
Many thanks for your help in advance.
Hi again guys,
Finally I managed to work it out. Silly me!
The solution to the above is as follows :
etypeid < 10 ? "000" + (dt_str,1,1252)etypeid : etypeid > 10 && etypeid < 100 ? "00" + (dt_str,2,1252)etypeid : "0" + (dt_str,3,1252)etypeid
Sorry for the bother SSIS friends
|||Mark your post as an answer, please.Sunday, February 19, 2012
How to build an string alias in T-SQL
I have the following stored procedure:
SELECT
SERVER_NAME,SERVICE_PORT,
SERVER_NAME + ',' + SERVICE_PORT
ASSERVER_AND_PORTFROM
DEF_SERVICE_SETTINGSI want the 3rd column to be in format: SERVER_NAME + "," + SERVICE_PORT
But SQL gives error. Sees "," as column.
How can I fix this?
Which database and language you are using?|||SQL-server
Column SERVER_NAME is varchar type
Column SERVICE_PORT is int type
My code works when both type of columns are of varchar, but the SERVICE_PORT column is of int type.
Can I cast the int type to a varchar type in some way?
|||Found it:
SERVER_NAME +','+CAST(SERVICE_TCP_PORTAs varchar(1000))ASSERVER_AND_PORT
|||Yes you have to Cast.
SERVER_NAME + ',' + Cast(SERVICE_PORT as varchar) AS SERVER_AND_PORT
|||convert(varchar(50), SERVICE_PORT)
HTH