Showing posts with label execute. Show all posts
Showing posts with label execute. Show all posts

Thursday, March 8, 2012

Change the table structure

Hi...

I execute select statement on three tables and i get the following table:

ID

Value

Name

1

10

color

2

20

color

3

30

color

4

40

color

and, from this table i want to create the following table:

ID

color

1

10

2

20

3

30

4

40

mean, the value color become the header title of the column.

How can i do that?

thank you...

But you use a GridView or what to show the table ?

If you use a GridView you can set the Visible attribute of a BoundField at runtime.

|||

Hi...

I am not using gridView, or any other control, i just need to do this in sql.

thanks.

|||

may215:

Hi...

I am not using gridView, or any other control, i just need to do this in sql.

thanks.

Are you going to insert values in the second table, or its value will be same as the first table but columns' names are diffrents?

If you are not going to insert values in the second table, then I suggest to create a view that get its data from the first table.

1CREATE VIEW MyViewForTheSecondTable23AS45SELECT [ID], [VALUE]AS'Color'67FROM MyFirstTable8910

Now, you can do the SELECT on the view like:

1SELECT *FROM MyViewForTheSecondTable

The returned result will be same as in the first table but columns name will be ID and Color insted of ID and Value.

Good luck.

|||

Hi...

When i try to create the view i am getting error: invalid column name ID, VALUE....in the following example: invalid column name PhonePropertyValue , PhonePropertyName.

here is the full example i trying to do:

SELECT [dbo.TblPropertyForPhoneType.PhonePropertyValue], [dbo.TblPhoneProperty.PhonePropertyName] AS
'color'

FROM dbo.TblPhoneType INNER JOIN
dbo.TblPropertyForPhoneType ON dbo.TblPhoneType.PhoneTypeID = dbo.TblPropertyForPhoneType.PhoneTypeID INNER JOIN
dbo.TblPhoneProperty ON dbo.TblPropertyForPhoneType.PhonePropertyID = dbo.TblPhoneProperty.PhonePropertyID
WHERE (dbo.TblPhoneProperty.PhonePropertyID = '34')

Why is that?

thanks...

|||

may215:

Hi...

When i try to create the view i am getting error: invalid column name ID, VALUE....i

I cheked the example I wrote .. it is working fine.

Here is a complete senario that worked on my machine and it should work on your machine as well:

1-- create sample database2create database MyTestDB3go45-- use the sample database6use MyTestDB7go89-- create new table for testing10CREATE TABLE MyTable11(12[ID]INT,13[VALUE]CHAR(10)14)15GO1617-- insert two records in the testing table18INSERT INTO MyTableSELECT 4,'red'19INSERT INTO MyTableSELECT 5,'black'202122-- create a view23CREATE VIEW MyViewForTheSecondTable2425AS2627 SELECT [ID], [VALUE]AS'COLOR'2829FROM MyTable303132-- select data from the created view33SELECT *FROM MyViewForTheSecondTable

Please let me know if it did not work with you for any reason.

may215:

in the following example: invalid column name PhonePropertyValue , PhonePropertyName.

here is the full example i trying to do:

SELECT [dbo.TblPropertyForPhoneType.PhonePropertyValue], [dbo.TblPhoneProperty.PhonePropertyName] AS
'color'

FROM dbo.TblPhoneType INNER JOIN
dbo.TblPropertyForPhoneType ON dbo.TblPhoneType.PhoneTypeID = dbo.TblPropertyForPhoneType.PhoneTypeID INNER JOIN
dbo.TblPhoneProperty ON dbo.TblPropertyForPhoneType.PhonePropertyID = dbo.TblPhoneProperty.PhonePropertyID
WHERE (dbo.TblPhoneProperty.PhonePropertyID = '34')

Why is that?

thanks...

First of all, please make sure those columns are exists in the table and they were typed correctly.

Then try this:

1SELECT prop.PhonePropertyValue, prop.PhonePropertyNameAS'color'23FROM dbo.TblPhoneType pt4INNERJOIN5 dbo.TblPropertyForPhoneType prop6ON pt.PhoneTypeID = prop.PhoneTypeID7INNERJOIN8 dbo.TblPhoneProperty pp9ON pp.PhonePropertyID = prop.PhonePropertyID10WHERE pp.PhonePropertyID ='34'11

Good luck.

Change the Shared Data Source when deploying

I am trying to move my reports (and data sources) from one server to another.
I can move everything fine, but when I go to execute a report, it says
invalid data source, even though the data source exists with the same name as
it did on the original server. I can manually go through each report and
point them to the data source and it works fine, but I need to get this
working with little or no intervention.
--
JasonMake sure you create the shared datasource first before deploying any
reports that reference it, it should get picked up fine then.
--
HTH
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
"JasonDWilson" <JasonDWilson@.discussions.microsoft.com> wrote in message
news:8005DE7C-15C1-4AAC-82C4-83F1C3FFDB75@.microsoft.com...
>I am trying to move my reports (and data sources) from one server to
>another.
> I can move everything fine, but when I go to execute a report, it says
> invalid data source, even though the data source exists with the same name
> as
> it did on the original server. I can manually go through each report and
> point them to the data source and it works fine, but I need to get this
> working with little or no intervention.
> --
> Jason

Friday, February 10, 2012

Change minimum database size from 3mb to 2mb

Hi
I have been using sql express so far with my FileManager database.
Since I migrated to SQL 2005 developer edition, I am unable to execute
sql script created from FileManager database before uninstalling sql
express.
Code:
USE [master]
GO
/****** Object: Database [FileManager] Script Date: 11/14/2007
19:58:28 ******/
CREATE DATABASE [FileManager] ON PRIMARY
( NAME = N'FileManager', FILENAME = N'c:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\DATA\FileManager.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'FileManager_log', FILENAME = N'c:\Program Files\Microsoft
SQL Server\MSSQL.1\MSSQL\DATA\FileManager_log.ldf' , SIZE = 1024KB ,
MAXSIZE = 2048GB , FILEGROWTH = 10%)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO
.
.
.
Error:
Msg 1803, Level 16, State 1, Line 2
The CREATE DATABASE statement failed. The primary file must be at
least 3 MB to accommodate a copy of the model database.
How do i correct that.
Regards
Piotr KolodziejThe error message tell you what the problem is. The model database determines the minimum database
size. The size of model in 2005 (data file) is 3MB, which is why you can't make the new database
smaller. You could shrink model first, but I do not recommend that solution. Amend your script
instead and make the new database a reasonable size.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Piotrekk" <Piotr.Kolodziej@.gmail.com> wrote in message
news:6ef9dfd8-9cee-4ba2-82aa-bf09176b79bb@.b36g2000hsa.googlegroups.com...
> Hi
> I have been using sql express so far with my FileManager database.
> Since I migrated to SQL 2005 developer edition, I am unable to execute
> sql script created from FileManager database before uninstalling sql
> express.
> Code:
> USE [master]
> GO
> /****** Object: Database [FileManager] Script Date: 11/14/2007
> 19:58:28 ******/
> CREATE DATABASE [FileManager] ON PRIMARY
> ( NAME = N'FileManager', FILENAME = N'c:\Program Files\Microsoft SQL
> Server\MSSQL.1\MSSQL\DATA\FileManager.mdf' , SIZE = 2048KB , MAXSIZE => UNLIMITED, FILEGROWTH = 1024KB )
> LOG ON
> ( NAME = N'FileManager_log', FILENAME = N'c:\Program Files\Microsoft
> SQL Server\MSSQL.1\MSSQL\DATA\FileManager_log.ldf' , SIZE = 1024KB ,
> MAXSIZE = 2048GB , FILEGROWTH = 10%)
> COLLATE SQL_Latin1_General_CP1_CI_AS
> GO
> .
> .
> .
>
> Error:
> Msg 1803, Level 16, State 1, Line 2
> The CREATE DATABASE statement failed. The primary file must be at
> least 3 MB to accommodate a copy of the model database.
>
> How do i correct that.
> Regards
> Piotr Kolodziej|||Hello,
You can not create database files less than your model database's database
files.
By default, model database has a 3MB in size mdf file and 1MB in size ldf
file. So you can not create a data file (mdf) less than 3MB in this
situation. If you want to
create a 2MB in size data file, then go and change your model databases mdf
data file size and set it 2MB. Then you'll be able to run your following
code successfully.
--
Ekrem Önsoy
"Piotrekk" <Piotr.Kolodziej@.gmail.com> wrote in message
news:6ef9dfd8-9cee-4ba2-82aa-bf09176b79bb@.b36g2000hsa.googlegroups.com...
> Hi
> I have been using sql express so far with my FileManager database.
> Since I migrated to SQL 2005 developer edition, I am unable to execute
> sql script created from FileManager database before uninstalling sql
> express.
> Code:
> USE [master]
> GO
> /****** Object: Database [FileManager] Script Date: 11/14/2007
> 19:58:28 ******/
> CREATE DATABASE [FileManager] ON PRIMARY
> ( NAME = N'FileManager', FILENAME = N'c:\Program Files\Microsoft SQL
> Server\MSSQL.1\MSSQL\DATA\FileManager.mdf' , SIZE = 2048KB , MAXSIZE => UNLIMITED, FILEGROWTH = 1024KB )
> LOG ON
> ( NAME = N'FileManager_log', FILENAME = N'c:\Program Files\Microsoft
> SQL Server\MSSQL.1\MSSQL\DATA\FileManager_log.ldf' , SIZE = 1024KB ,
> MAXSIZE = 2048GB , FILEGROWTH = 10%)
> COLLATE SQL_Latin1_General_CP1_CI_AS
> GO
> .
> .
> .
>
> Error:
> Msg 1803, Level 16, State 1, Line 2
> The CREATE DATABASE statement failed. The primary file must be at
> least 3 MB to accommodate a copy of the model database.
>
> How do i correct that.
> Regards
> Piotr Kolodziej