sql語句

 1.select top 12 * from JackDonkey_Album where AlbumId in(select AlbumId from JackDonkey_TagImgThou whereCONVERT(varchar(50), TagId) ='489') and RowStatus='active' order by YesCount DESC

2.((select * from (select top 13 'Picture' as ImgCat, a.ImgNameas Name,a.ImgId as ImgId,
 a.ImgUrl as ImgUrl, b.UserName as Username,a.CreatedDate as CreatedDate, b.DonkeyShowCountas DSC from JackDonkey_Picture
  a,JackDonkey_User b
where a.ImgId in (select ImgId from JackDonkey_TagImgThou where TagId=45)
  and a.rowstatus='active' and b.userid=a.UserId order by a.CreatedDate desc)abc)
  Union all(select * from (select top 13  'Album' as ImgCat, a.AlbumName as Name,a.AlbumId as ImgId,a.BigImgUrl
  as ImgUrl,b.UserName as Username,a.CreatedDate as CreatedDate,b.DonkeyShowCount as DSC from JackDonkey_Album a,
  JackDonkey_User b where a.AlbumId in (select AlbumId from JackDonkey_TagImgThou where TagId=45) and a.rowstatus='active'
   and b.userid=a.UserId order by a.CreatedDate desc) abc) Union all(select * from (select top 13 'Profile' as ImgCat,
   Username as Name, Userid as ImgId, AvatarImg as ImgUrl, UserName as USername,CreatedDate as CreatedDate,DonkeyShowCount
   as DSC from JackDonkey_User where UserId in (select UserId from JackDonkey_UserThought where  Id in (select ThouId
   from JackDonkey_TagImgThou where TagId=45)) and UserType=1 and isactive =1 and rowstatus='active'
   order by CreatedDate desc) abc)) order by CreatedDate DESC
  

2".(SELECT  a.*,b.userid,'P' as imageTypeFROM JackDonkey_PictureComment a
inner join JackDonkey_Picture b on a.PictureId=b.ImgId
 Where b.userid=24
 
 union all
 
SELECT a.id as id ,a.AlbumId as PictureId,a.userid as UserId, a.UserName as UserName,
 a.Comment as Comment ,a.RowStatus as RowStatus,
 a.CreatedDate as CreatedDate, a.YesCount as YesCount,a.NoCount as NoCount ,b.userid as userid ,'A' as imageType
 FROM JackDonkey_AlbumComment a inner join JackDonkey_Album b on a.AlbumId=b.AlbumId 
 Where b.userid=24 and a.RowStatus='active'
 
 union all
 
SELECT a.id as id ,a.ThoughtId as PictureId,a.UserId as UserId, a.UserName as UserName,
a.Comment as Comment ,a.RowStatus as RowStatus, a.CreatedDate as CreatedDate, a.YesCount as YesCount,
a.NoCount as NoCount ,b.userid as userid ,'T' as imageType
FROM JackDonkey_UserThoughtComment a inner join JackDonkey_UserThought b on a.ThoughtId=b.Id 
Where b.userid=24 and a.RowStatus='active'
 
 )
 order by a.createddate desc


3. SQL 更新操作:update JackDonkey_User set Tag1=‘11’,Tag2=‘11’,Tag3=‘1’ where UserId=1

4.JTD:   string str = txtTags.Text.Trim();
        char strsplit = ',';
        string[] tags = str.Split(strsplit);
          // savs to the SQL
         string strconn = System.Configuration.ConfigurationManager.AppSettings["Main.ConnectionString"].Trim() + " ; Provider=SQLOLEDB;";
        OleDbConnection cnn = new OleDbConnection(strconn);
        string sql = "select *  from JackDonkey_Tag  where TagId in (select TagId from  JackDonkey_TagImgThou where ImgId=" + lblPicId.Text + " ) order by TagId";
        try
        {
            cnn.Open();
            OleDbCommand cmd = new OleDbCommand(sql, cnn);
            OleDbDataReader read = cmd.ExecuteReader();
            List<int> TagId = new List<int>();
            while (read.Read())
            {               
                TagId.Add(Convert.ToInt32 (read["TagId"]));
            }
            //update TagName
            for (int i = 0; i < TagId.Count;i++ )
            {
                string sql_update = "update JackDonkey_Tag set TagName='" + tags[i] + "' where TagId=" + TagId[i];
                OleDbCommand cmd_update = new OleDbCommand(sql_update, cnn);
                cmd_update.ExecuteNonQuery();
            }
        }
        catch (Exception ex)
        {
            if (cnn.State == ConnectionState.Open)
            {
                cnn.Close();
            }
        }

發佈了35 篇原創文章 · 獲贊 2 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章