首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

用sql输出正弦曲线,该怎么处理

2012-04-15 
用sql输出正弦曲线就当活跃活跃气氛吧~[解决办法]竖着的行不行?俺还不会行列转换~SQL codedeclare @x floa

用sql输出正弦曲线
就当活跃活跃气氛吧~


[解决办法]
竖着的行不行?俺还不会行列转换~

SQL code
declare @x floatdeclare @tb table(y float)set @x = 0while @x < 360  begin    insert into  @tb select ROUND(SIN(RADIANS(@x)) * 100,0)    set @x = @x + 5  end   select space(201 + y - 100 )+ '*' from @tb----------------------------------------------------------------------------------------------------------------                                                                                                     *                                                                                                              *                                                                                                                      *                                                                                                                               *                                                                                                                                       *                                                                                                                                               *                                                                                                                                                       *                                                                                                                                                              *                                                                                                                                                                     *                                                                                                                                                                            *                                                                                                                                                                                  *                                                                                                                                                                                       *                                                                                                                                                                                            *                                                                                                                                                                                                *                                                                                                                                                                                                   *                                                                                                                                                                                                      *                                                                                                                                                                                                       *                                                                                                                                                                                                         *                                                                                                                                                                                                         *                                                                                                                                                                                                         *                                                                                                                                                                                                       *                                                                                                                                                                                                      *                                                                                                                                                                                                   *                                                                                                                                                                                                *                                                                                                                                                                                            *                                                                                                                                                                                       *                                                                                                                                                                                  *                                                                                                                                                                            *                                                                                                                                                                     *                                                                                                                                                              *                                                                                                                                                       *                                                                                                                                               *                                                                                                                                       *                                                                                                                               *                                                                                                                      *                                                                                                              *                                                                                                     *                                                                                            *                                                                                    *                                                                           *                                                                   *                                                           *                                                   *                                            *                                     *                              *                        *                   *              *          *       *    *   * * * *   *    *       *          *              *                   *                        *                              *                                     *                                            *                                                   *                                                           *                                                                   *                                                                           *                                                                                    *                                                                                            * 


[解决办法]

SQL code
CREATE PROCEDURE P_DrawSin(@BeDegree decimal (10,2),@EdDegree decimal (10,2))AS SET NOCOUNT ONDECLARE @PAR VARCHAR(50)SET @PAR=CONVERT(VARCHAR,@BeDegree)IF (CONVERT(INT,@BeDegree)%10)<>0BEGIN    RAISERROR('"%s" 不是10的倍数,请录入10的倍数参数',12,16,@PAR)    RETURNENDSET @PAR=CONVERT(VARCHAR,@EdDegree)IF (CONVERT(INT,@EdDegree)%10)<>0BEGIN    RAISERROR('"%s" 不是10的倍数,请录入10的倍数参数',12,16,@PAR)    RETURNEND  DECLARE @TB TABLE (ADegrees Decimal (10,2),ASine Decimal (10,2))DECLARE @TC TABLE (ADegrees Decimal (10,2),ASine Decimal (10,2))DECLARE @Sine Decimal (10,2),@Radians   Decimal (10,2),@Degrees Decimal (10,2),@Tmp1 Decimal (10,2),@Tmp2 INTDECLARE @SQL VARCHAR(8000),@SQLTMP VARCHAR(8000),@RE VARCHAR(8000)SELECT @Radians = Radians(Convert(Float,@BeDegree)),@Degrees=@BeDegreeWHILE  (@Degrees<=@EdDegree)BEGIN    SET @Sine=ROUND(SIN(@Radians)*10,0)    INSERT INTO @TB SELECT @Degrees,@Sine    SET @Degrees=@Degrees+10    SET @Radians= RADIANS(CONVERT(FLOAT,@Degrees))ENDDECLARE SinCURSOR CURSOR READ_ONLY FOR     SELECT ADegrees=MIN(ADegrees),ASine FROM @TB GROUP BY ASine ORDER BY ASine  DescOPEN SinCURSORFETCH NEXT FROM SinCURSOR INTO @Degrees,@SineWHILE (@@FETCH_STATUS <> -1)BEGIN    IF @Sine=0        SET @PAR='0'    ELSE         SET @PAR='*'    SET @SQL='SPACE('+CONVERT(VARCHAR(10),CEILING(@Degrees-@BeDegree))+'/10)+'''+@PAR+''''    IF EXISTS (SELECT 1 FROM @TB WHERE ADegrees<>@Degrees AND ASine=@Sine)    BEGIN        DELETE @TC        INSERT INTO @TC SELECT ADegrees,@Sine FROM @TB WHERE ASine=@Sine ORDER BY  ADegrees        SELECT @Tmp1=NULL,@Tmp2=NULL        UPDATE @TC        SET @Tmp1=@Tmp2,            @Tmp2=ADegrees,            @SQLTMP=ISNULL(@SQLTMP,'')+'+SPACE('+CONVERT(VARCHAR(10),(ABS(ADegrees-@Tmp1)/10)-1)++')+'''+@PAR+''''        WHERE ASine=@Sine    END    SELECT @RE=CASE WHEN @RE IS NULL THEN '' ELSE @RE+'+CHAR(10)+CHAR(13)+' END + @SQL+ISNULL(@SQLTMP,'')     SET @SQL=''    SET @SQLTMP=''    FETCH NEXT FROM SinCURSOR INTO @Degrees,@SineENDCLOSE SinCURSORDEALLOCATE SinCURSOREXEC ('PRINT '+@RE)SET NOCOUNT  OFF--测试exec dbo.P_DrawSin 0,1800/*        ***                                 ***      **   **                             **   **     *       *                           *       *    *         *                         *         *   *           *                       *           *  *             *                     *             * *               *                   *               *0                 0                 0                 0                 0                   *               *                   *               *                    *             *                     *             *                     *           *                       *           *                      *         *                         *         *                       *       *                           *       *                        **   **                             **   **                          ***                                 ****/ 

热点排行