dbTalk Databases Forums  

Re: incomprshensible code

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Re: incomprshensible code in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Roy Harvey (SQL Server MVP)
 
Posts: n/a

Default Re: incomprshensible code - 11-14-2007 , 03:03 PM






On Wed, 14 Nov 2007 11:05:00 -0800, J?dru? <anowacki.pila (AT) interia (DOT) pl>
wrote:

Quote:
Hello

My friend gave me stored procedure, and I understand this code:

create table t (x varchar(50), y int)
Create an empty table. The table has two columns, one varying length
and one integer.

Quote:
insert into t (x)
We are going to INSERT new rows(s) into the table, but only assign
data to the column named x.

Quote:
select 'bob' + char(1) + 'fred'
The source of data for the INSERT is the result set of a SELECT. The
SELECT does not read any table, it just returns one row. The one
column in the result set is a character string made up by
concatenating (using the + operator) three other strings. The string
in the middle is created using the CHAR function. The CHAR function
converts a number ranging from 0 to 255 into an ASCII character. The
ASCII character that corresponds to 1 is not a printable character;
for me the results look like an empty square.

Quote:
select * from t
This returns the one row of the table.
x y
-------------------------------------------------- -----------
bob
fred NULL

Quote:
Please explain me and corect this code.
The code is correct, though it looks like a simple example of
something rather than anything of actual use.

Roy Harvey
Beacon Falls, CT


Reply With Quote
  #2  
Old   
J dru
 
Posts: n/a

Default Re: incomprshensible code - 11-14-2007 , 04:42 PM






On 14 Lis, 21:03, "Roy Harvey (SQL Server MVP)" <roy_har... (AT) snet (DOT) net>
wrote:
Quote:
On Wed, 14 Nov 2007 11:05:00 -0800, J?dru? <anowacki.p... (AT) interia (DOT) pl
wrote:

Hello

My friend gave me stored procedure, and I understand this code:

create table t (x varchar(50), y int)

Create an empty table. The table has two columns, one varying length
and one integer.

insert into t (x)

We are going to INSERT new rows(s) into the table, but only assign
data to the column named x.

select 'bob' + char(1) + 'fred'

The source of data for the INSERT is the result set of a SELECT. The
SELECT does not read any table, it just returns one row. The one
column in the result set is a character string made up by
concatenating (using the + operator) three other strings. The string
in the middle is created using the CHAR function. The CHAR function
converts a number ranging from 0 to 255 into an ASCII character. The
ASCII character that corresponds to 1 is not a printable character;
for me the results look like an empty square.

select * from t

This returns the one row of the table.
x y
-------------------------------------------------- -----------
bob
fred NULL

Please explain me and corect this code.

The code is correct, though it looks like a simple example of
something rather than anything of actual use.

Roy Harvey
Beacon Falls, CT
Thank You very much.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.